2015-11-12 28 views

回答

2

描述用於解釋正在進行的工作。通常你會描述一個課程,它將圍繞所有的it調用。 it是/是本describe塊內執行的測試用例(多個):

describe Foo do 
    it "will return true" do 
    expect(Foo.bar).to eq(true) 
    end 

    it "will return false" do 
    expect(Foo.baz).to eq(false) 
    end 
end 

# When run, rspec output is: 
Foo 
    will return true 
    will return false 

在上述情況下,it方法描述barbaz如何將在Foo類發揮作用。 A good read is the rspec documentation on this.

+0

'它'就像我們在'java'中'class'中的方法。我們也可以使用點運算符在其他方法中重用它,例如'Foo.will return true'。請舉個例子,如果我不正確的做法。 「def」來自哪裏? – paul

+1

@paul'def'是如何在Ruby中定義方法的。既然你不確定'def'有什麼用,我建議你閱讀一些學習資料,例如:http://learnrubythehardway.org/book/它會爲你提供Ruby編程所需的基礎知識。 –

+0

好的。以及如何在其他'it'中使用'it'。它會按照我之前評論中的方式工作嗎? – paul

相關問題