Forum: Ruby on Rails Assert_select with count 0

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aa W. (Guest)
on 2009-02-03 00:06
Hello, all.  This is short and simple.  I have this statement in a
functional test:

assert_select 'input' do
      assert_select "[name=?]", {:count => 0,:text =>/areas\[1\]/}
    end
This assertion gives me the following:


  1) Failure:
test_areas(SampleControllerTest)
    [c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/asse
rtions/selector_assertions.rb:281:in `assert_select'
     test/functional/sample_controller_test.rb:315:in `test_areas'
     c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/asse
rtions/selector_assertions.rb:294:in `assert_select'
     test/functional/sample_controller_test.rb:312:in `test_areas']:
Expected at least 1 elements, found 0.
<false> is not true.

Since I've explicitly used :count => 0, I can't for the life of me
figure out why it's expecting at least 1 element.  I'm certain that this
is the source of the failure, and not something else in the test,
because I have achieved success by commenting only the line with
assert_select "[name=?]", {:count => 0,:text =>/areas\[1\]/}.

Thanks in advance for your time.
Aa W. (Guest)
on 2009-02-03 18:13
Hello, again.  I just wanted to post this here for the future help of
anyone searching the archives.

This works:

assert_select ["[name=?]", "areas[1]"], {:count => 0}

Evidently, the areas[1] is a part of the selector (which can be
specified as an array), and not the "text" value of the hash.

Cheers.

Aa Wilson wrote:
> Hello, all.  This is short and simple.  I have this statement in a
> functional test:
>
> assert_select 'input' do
>       assert_select "[name=?]", {:count => 0,:text =>/areas\[1\]/}
>     end
> This assertion gives me the following:
>
>
>   1) Failure:
> test_areas(SampleControllerTest)
>     [c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/asse
> rtions/selector_assertions.rb:281:in `assert_select'
>      test/functional/sample_controller_test.rb:315:in `test_areas'
>      c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/asse
> rtions/selector_assertions.rb:294:in `assert_select'
>      test/functional/sample_controller_test.rb:312:in `test_areas']:
> Expected at least 1 elements, found 0.
> <false> is not true.
>
> Since I've explicitly used :count => 0, I can't for the life of me
> figure out why it's expecting at least 1 element.  I'm certain that this
> is the source of the failure, and not something else in the test,
> because I have achieved success by commenting only the line with
> assert_select "[name=?]", {:count => 0,:text =>/areas\[1\]/}.
>
> Thanks in advance for your time.
This topic is locked and can not be replied to.