Forum: RSpec have_tag + quantity - question

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.
0f46ce797c86a2bd7142ac40de29f6e3?d=identicon&s=25 Mateusz Winiarski (mawiniarski)
on 2009-03-06 09:48
(Received via mailing list)
Greetings,

Is there a way to check quantity of tags?

Something like this:

response.should have_tag('div').quantity(4)

Thanks.
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-06 09:56
(Received via mailing list)
On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniarski@gmail.com>
wrote:
> Greetings,
>
> Is there a way to check quantity of tags?
>
> Something like this:
>
> response.should have_tag('div').quantity(4)

response.should have_tag('div', 4)

Check the assert_select docs (have_tag wraps it) at
http://api.rubyonrails.org/classes/ActionControlle...

Cheers,
David
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2009-03-06 16:18
(Received via mailing list)
On Thu, Mar 5, 2009 at 5:40 AM, MAwiniarski <MAwiniarski@gmail.com>
wrote:
> Greetings,
>
> Is there a way to check quantity of tags?
>
> Something like this:
>
> response.should have_tag('div').quantity(4)

Another great resource is
http://labnotes.org/svn/public/ruby/rails_plugins/...

///ark
994e42bda994be2cd1d791f18ee6d561?d=identicon&s=25 Stephen Eley (Guest)
on 2009-03-06 21:48
(Received via mailing list)
On Fri, Mar 6, 2009 at 3:55 AM, David Chelimsky <dchelimsky@gmail.com>
wrote:
> On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniarski@gmail.com> wrote:
>>
>> Is there a way to check quantity of tags?
>
> response.should have_tag('div', 4)

Ooh!  Thank you; I wish I'd known that before.  All this time I've
been using annoyingly complicated xpath tests:

Then /^I should see (\d+) people$/ do |num|
  response.should
have_xpath("//*[count(*[contains(@class,'person')])=#{num}]")
end


--
Have Fun,
   Steve Eley (sfeley@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
3399cbfb9e5fec93c324789b29309911?d=identicon&s=25 Pat Nakajima (patnakajima)
on 2009-03-06 23:44
(Received via mailing list)
I've posted it on this list before, but if you're writing view tests,
check
out Elementor:
http://pivotallabs.com/users/patn/blog/articles/60....
It provides a much cleaner way of asserting on markup, and doesn't
require
you to litter your expectations with CSS selectors.
0f46ce797c86a2bd7142ac40de29f6e3?d=identicon&s=25 Mateusz Winiarski (mawiniarski)
on 2009-03-07 15:42
(Received via mailing list)
Thanks.
This topic is locked and can not be replied to.