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

Gordon anexiole at gmail.com
Fri Nov 18 06:18:11 EST 2011


Hi guys,

I tried reading up the RSPEC Book (Dec 2010) and googled a bit but  I
could not find anything.

I'm using Rspec2.

Example:


spec/factories/categories.rb
======================

FactoryGirl.define do
  factory :category_intakes, :class => 'category' do
    name        'intakes and filters'
    description 'airfilters and etc.'
    created_by  1
    updated_by  1
  end

  factory :category_audio, :class => 'category' do
    name        'audio'
    description 'in car entertainment'
    created_by  1
    updated_by  1
  end
end

spec/views/categories/index.html.erb
=============================

require 'spec_helper'

describe "categories/index.html.erb" do
  before(:each) do
    assign( :categories, [
            FactoryGirl.create(:category_intakes),
            FactoryGirl.create(:category_audio),
        ]
    )
  end

  it "renders a list of categories" do
    render
    assert_select "tr>td", :text => "intakes and filters".to_s, :count
=> 1
    assert_select "tr>td", :text => "audio".to_s, :count => 1
  end
end



I noticed that the index view spec above passes but when I change the
count to 2, it fails saying that only 1 element is expected.

Question:

1) what does :count actually mean? Does it mean the total number of
fixture objects expected?
2) does the ordering of the rendered fixture items matter
( ie. :category_audio is expected before :category_intakes)?


More information about the rspec-users mailing list