0
我有這樣的測試:方括號
def test_should_only_list_promoted_on_index
get :index
assert_equal stories(:promoted), assigns(:stories)
end
其失敗消息:
<#<Story id: 3, name: "What is a Debugger?", link: "http://en.wikipedia.org/wiki/Debugger", created_at: "2011-03-25 20:57:04", updated_at: "2011-03-25 20:57:04", user_id: 2, votes_count: 5, description: nil>> expected but was
<[#<Story id: 3, name: "What is a Debugger?", link: "http://en.wikipedia.org/wiki/Debugger", created_at: "2011-03-25 20:57:04", updated_at: "2011-03-25 20:57:04", user_id: 2, votes_count: 5, description: nil>]>.
但是如果我把方括號圍繞
「(:提拔)的故事」參數
def test_should_only_list_promoted_on_index
get :index
assert_equal [stories(:promoted)], assigns(:stories)
end
測試成功。爲什麼是這樣?
我使用的Rails 2.3.9和Ruby 1.9.2