当我尝试实现“Fakeweb”时出现此错误,但我不明白这个问题。
场景:“用户填写完所有信息后,系统将使用“fbid”属性之一进行验证,如果成功则只会创建一个新公司,否则该过程将失败。
Failures:
1) Companies new company create with valid information correct facebook id validates facebook id
Failure/Error: it "should create a company" do
NoMethodError:
undefined method `it' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_3::Nested_1::Nested_1:0x00000102fb84e0>
# ./spec/requests/companies_spec.rb:40:in `block (5 levels) in <top (required)>'
公司_spec.rb
describe "correct facebook id" do
#validate fbid
it "validates facebook id" do
FakeWeb.register_uri(:head, "http://graph.facebook.com/examplecompany", :username => 'examplecompany')
Company.new(:url => "http://graph.facebook.com/examplecompany").fb_id_string.should eq('examplecompany')
it "should create a company" do
expect { click_button submit }.to change(Company, :count).by(1)
end
型号/公司.rb
def fb_id_string
uri = URI.parse(url)
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request_head(uri.path) }
response["username"].to_str
end
结尾