[rspec-users] What does :count actually mean in assert_select?

Gordon Yeong anexiole at gmail.com
Fri Nov 18 06:29:23 EST 2011


I think i answered my own question. :count refers to the number of fixture
objects.


The reason why :count => 2 was passing for  views index specs is because  2
objects are being mocked and they are identical.


Hence, there are 2 stock tests:

1) asserts that there are 2 <td> elements which have the name of 'Name'

2) asserts that there are 2 <td> elements which have the name of
'Description'


 This is what a stock view index spec looks like:
---- Stock index spec view ----

describe "makes/index.html.erb" do
  before(:each) do
    assign(:makes, [
      stub_model(Make,
        :name => "Name",
        :description => "Description",
        :created_by => "",
        :updated_by => ""
      ),
      stub_model(Make,
        :name => "Name",
        :description => "Description",
        :created_by => "",
        :updated_by => ""
      )
    ])
  end

  it "renders a list of makes" do
    render
    # Run the generator again with the --webrat flag if you want to use
webrat matchers
    assert_select "tr>td", :text => "Name".to_s, :count => 2
    # Run the generator again with the --webrat flag if you want to use
webrat matchers
    assert_select "tr>td", :text => "Description".to_s, :count => 2
  end
end
---- Stock index spec view ----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20111118/6686fe8f/attachment.html>


More information about the rspec-users mailing list