我对 rspec 非常陌生,我正在尝试编写一个测试以确保创建的对象确实存在。这是我的测试现在的样子:
require 'spec_helper'
describe "UserService" do
describe ".new" do
it "should create a UserService object" do
service = UserService.new
service.should_not be_nil
end
end
end
问题是,我在运行测试时得到了这个输出:
1) UserService.new should create a UserService object
Failure/Error: service = UserService.new
Errno::ECONNREFUSED:
Connection refused - connect(2)
# ./spec/requests/user_service_spec.rb:6:in `new'
# ./spec/requests/user_service_spec.rb:6:in `block (3 levels) in <top (required)>'
我希望此时连接被拒绝,但我怎样才能测试它而不是破坏测试呢?或者,我看到的是正确的输出吗?谢谢!