[rspec-users] Testing for the number of occurrences of a word

Bart Zonneveld loop at superinfinite.com
Tue Mar 10 11:53:20 EDT 2009


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 &lts and &gts  
>> 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(/&lt;record&gt;/)
   matches.length.should == num.to_i
end


More information about the rspec-users mailing list