开发者

Square Brackets on Assert Parameters in Rails

开发者 https://www.devze.com 2023-02-20 01:36 出处:网络
I have this test: def test_should_only_list_promoted_on_index get :index assert_equal stories(:promoted), assigns(:stories)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号