![](/img/trans.png)
[英]Simple Rspec Length Validation Test - NoMethodError: Undefined method `before' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fb8a24bac00>
[英]undefined method `it' in RSpec::Core::ExampleGroup::Nested_2
嘗試實現“ 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
的rspec nested it
不會產生任何結果,因此我想對@apneadiving的注釋進行詳細說明。
雖然rspec的允許describe
和任意嵌套它的同義詞,雖然it
是類似於describe
當傳遞字符串參數在其結構中, it
的塊只能包含嘲笑,預期,應用程序代碼和香草紅寶石。 它不能包含它的其他調用,或者就此而言,不能包含it
before
, after
或let
。 它可以調用subject
,但是這樣做只是調用了subject被定義為的代碼塊; 它不會重新定義主題。
相反,嘲笑和期望不能直接在describe
表達。 它們必須包含在it
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.