当我尝试实现“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)>'
companies_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
模型/company.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
结束
最佳答案
由于在 Google 上搜索 rspec Nested it
没有得到任何结果,我想我应该详细说明一下 @apneadiving 的评论。
虽然 rspec 允许 describe
及其同义词任意嵌套,但在传递字符串参数时,it
的结构与 describe
类似,一个 it
block 只能包含模拟、期望、应用程序代码和普通 Ruby。它不能包含对 it
或 before
、after
或 let
的其他调用。它可以调用 subject
,但这样做只会调用 subject 被定义为的 block ;它不会重新定义主题。
相反,模拟和期望不能直接在describe
中表达。它们必须包含在it
内。
关于ruby-on-rails - RSpec::Core::ExampleGroup::Nested_2 中未定义的方法 `it',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17807465/