Square Brackets on Assert Parameters in Rails
I have this test:
def test_should_only_list_promoted_on_index
get :index
assert_equal stories(:promoted), assigns(:stories)
end
which 开发者_如何学JAVAfails with the message:
<#<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>]>.
however if I put square braces around the "stories(:promoted)" param
def test_should_only_list_promoted_on_index
get :index
assert_equal [stories(:promoted)], assigns(:stories)
end
the test succeeds. Why is this?
I am using Rails 2.3.9 and Ruby 1.9.2
The square brackets indicates an array. Looks like stories(:promoted)
is returning just one story, whereas assigns(:stories)
returns a length-1 array containing that story.
精彩评论