Skip to content
This repository

Expected exactly 2 elements matching "tr > td", found 10 #504

Closed
petervandenabeele opened this Issue February 12, 2012 · 0 comments

2 participants

Peter Vandenabeele David Chelimsky
Peter Vandenabeele

This seems an obvious bug when more then 1 integer something_id or other integer column is present in a table.

The stub_models in a view test are generated by default as:

index.html.erb_spec.rb :

      stub_model(MyModel,
...
        :xxx_id => 1,
        :yyy_id => 1,
        :zzz => 1,
        :ttt => 1,
        :uuu => 1,

...
      ),
      stub_model(MyModel,
        :xxx_id => 1,
        :yyy_id => 1,
        :zzz => 1,
        :ttt => 1,
        :uuu => 1,

When the view tests scans such a rendered page ... it results in 10 matches of 1.to_s
instead of the expected 2.

     Failure/Error: assert_select "tr>td", :text => 1.to_s, :count => 2
     MiniTest::Assertion:
       Expected exactly 2 elements matching "tr > td", found 10..
       <10> expected but was
       <2>.

I presume the generator should use consecutive numbers.

I was able to find a simple work-around with changing the test into:

index.html.erb_spec.rb :

      stub_model(MyModel,
...
        :xxx_id => 1,
        :yyy_id => 2,
        :zzz => 3,
        :ttt => 4,
        :uuu => 5,

...
      ),
      stub_model(MyModel,
        :xxx_id => 1,
        :yyy_id =>21,
        :zzz => 3,
        :ttt => 4,
        :uuu => 5,

...

    assert_select "tr>td", :text => 1.to_s, :count => 2
    assert_select "tr>td", :text => 2.to_s, :count => 2
# etc.

It's a little embarassing that running rspec after a fresh migration
fails on this.

This is tested on versions:

rspec-rails (2.8.1)
  actionpack (>= 3.0)
  activesupport (>= 3.0)
  railties (>= 3.0)
  rspec (~> 2.8.0)

In combination with Rails 4.0.0.beta
(version 3092324ef4e2f6f096adfbc of 10 Feb 2012)

David Chelimsky dchelimsky closed this in 88ed708 February 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.