簡體   English   中英

RSpec :: Core :: ExampleGroup :: Nested_2中未定義的方法'it'

[英]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 itrspec nested it不會產生任何結果,因此我想對@apneadiving的注釋進行詳細說明。

雖然rspec的允許describe和任意嵌套它的同義詞,雖然it是類似於describe當傳遞字符串參數在其結構中, it的塊只能包含嘲笑,預期,應用程序代碼和香草紅寶石。 它不能包含它的其他調用,或者就此而言,不能包含it beforeafterlet 它可以調用subject ,但是這樣做只是調用了subject被定義為的代碼塊; 它不會重新定義主題。

相反,嘲笑和期望不能直接在describe表達。 它們必須包含在it

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM