[英]RSpec puts different from should equal value
我無法理解為什么下面的代碼塊沒有通過,即使puts值顯示我正在檢查的值:
let(:new_on_each_example) { MovieList.new }
it "can use method defined by 'let'" do
new_on_each_example.should_not be_nil
# the object is memoized, so
new_on_each_example.should == new_on_each_example
puts new_on_each_example.class
new_on_each_example.class.should == "MovieList"
end
控制台顯示:
MovieList
預期:“MovieList”得到:MovieList(id:整數,標題:字符串,created_at:datetime,updated_at:datetime,track_number:整數)(使用==)
Puts顯示我正在尋找的值,但測試失敗。 為什么是這樣?
new_on_each_example.should be_instance_of(MovieList)
更多信息在rspec matchers doc中
您將轉到RSpec "MovieList"
。 這是一個字符串,而不是你班級的常數。 所以你應該這樣做:
new_on_each_example.class.should == MovieList
但是使用RSpec你也可以做一些更優雅的事情:
new_on_each_example.class.should be_a(MovieList)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.