Greetings, Is there a way to check quantity of tags? Something like this: response.should have_tag(''div'').quantity(4) Thanks.
On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniarski at 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/ActionController/Assertions/SelectorAssertions.html#M000547 Cheers, David> > Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Thu, Mar 5, 2009 at 5:40 AM, MAwiniarski <MAwiniarski at 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/assert_select/cheat/assert_select.html ///ark
On Fri, Mar 6, 2009 at 3:55 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniarski at 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 at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
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/608-better-view-testing-with-elementor. It provides a much cleaner way of asserting on markup, and doesn''t require you to litter your expectations with CSS selectors. On Fri, Mar 6, 2009 at 3:40 PM, Stephen Eley <sfeley at gmail.com> wrote:> On Fri, Mar 6, 2009 at 3:55 AM, David Chelimsky <dchelimsky at gmail.com> > wrote: > > On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniarski at 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 at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090306/0efb3605/attachment.html>
Thanks. On 6 Mar, 23:42, Pat Nakajima <patnakaj... at gmail.com> wrote:> 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/608-better-view-testi.... > It provides a much cleaner way of asserting on markup, and doesn''t require > you to litter your expectations with CSS selectors. > > On Fri, Mar 6, 2009 at 3:40 PM, Stephen Eley <sfe... at gmail.com> wrote: > > On Fri, Mar 6, 2009 at 3:55 AM, David Chelimsky <dchelim... at gmail.com> > > wrote: > > > On Thu, Mar 5, 2009 at 7:40 AM, MAwiniarski <MAwiniar... at 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 (sfe... at gmail.com) > > ? ESCAPE POD - The Science Fiction Podcast Magazine > > ?http://www.escapepod.org > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users