Bart Zonneveld
2009-Mar-10 12:16 UTC
[rspec-users] Testing for the number of occurrences of a word
Hey list, Quick question: How can I check that a given word appears a number of times on a page? The page in question includes some XML, rendered with <s and >s and I want to test that a given node exists 10 times on that page. thanks! bartz
Zach Dennis
2009-Mar-10 13:00 UTC
[rspec-users] Testing for the number of occurrences of a word
On Tue, Mar 10, 2009 at 8:16 AM, Bart Zonneveld <zuperinfinite at gmail.com> wrote:> Hey list, > > Quick question: How can I check that a given word appears a number of times > on a page? > The page in question includes some XML, rendered with <s and >s and I > want to test that a given node exists 10 times on that page.You want to make sure you have 10 nodes? Or that text shows up 10 times inside of any node? You can utilize Webrat''s #have_selector to count the nodes, ie: response.should have_selector("li", :count => 3)> > thanks! > bartz > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
aslak hellesoy
2009-Mar-10 13:05 UTC
[rspec-users] Testing for the number of occurrences of a word
On Tue, Mar 10, 2009 at 1:16 PM, Bart Zonneveld <zuperinfinite at gmail.com>wrote:> Hey list, > > Quick question: How can I check that a given word appears a number of times > on a page? > The page in question includes some XML, rendered with <s and >s and I > want to test that a given node exists 10 times on that page. >Here are a couple of ways to do it: http://lmgtfy.com/?q=ruby+count+occurrence+words count = # one of the solutions above count.should == 10 Cheers, Aslak> > thanks! > bartz > _______________________________________________ > 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/20090310/6fbb837e/attachment.html>
Bart Zonneveld
2009-Mar-10 15:37 UTC
[rspec-users] Testing for the number of occurrences of a word
On 10 mrt 2009, at 14:05, aslak hellesoy wrote:> > > On Tue, Mar 10, 2009 at 1:16 PM, Bart Zonneveld <zuperinfinite at gmail.com > > wrote: > Hey list, > > Quick question: How can I check that a given word appears a number > of times on a page? > The page in question includes some XML, rendered with <s and >s > and I want to test that a given node exists 10 times on that page. > > Here are a couple of ways to do it: http://lmgtfy.com/?q=ruby+count+occurrence+words > > count = # one of the solutions above > count.should == 10Argh, thanks to both of you. I was thinking too difficult, along the lines of have_tag(''my_div'', ''word'', 10)... cheers, bartz
Bart Zonneveld
2009-Mar-10 15:53 UTC
[rspec-users] Testing for the number of occurrences of a word
On 10 mrt 2009, at 16:37, Bart Zonneveld wrote:> On 10 mrt 2009, at 14:05, aslak hellesoy wrote: > >> On Tue, Mar 10, 2009 at 1:16 PM, Bart Zonneveld <zuperinfinite at gmail.com >> > wrote: >> Hey list, >> >> Quick question: How can I check that a given word appears a number >> of times on a page? >> The page in question includes some XML, rendered with <s and >s >> and I want to test that a given node exists 10 times on that page. >> >> Here are a couple of ways to do it: http://lmgtfy.com/?q=ruby+count+occurrence+words >> >> count = # one of the solutions above >> count.should == 10 > > Argh, thanks to both of you. > I was thinking too difficult, along the lines of have_tag(''my_div'', > ''word'', 10)...In case anyone was wondering how to do this: Then "I should see the last $num statuses of the user" do |num| matches = response.body.scan(/<record>/) matches.length.should == num.to_i end