rspec/rspec-rails — Issue #504: Expected exactly 2 elements matching "tr > td", found 10
Author: petervandenabeele
Created: 2012-02-12 19:03:01+00:00
State: open

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:

```ruby
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.

```ruby
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:

```ruby
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)