[rspec-users] Applying an rspec matcher against the elements of a collection

Pat Maddox mailinglists at patmaddox.com
Wed Feb 24 10:51:53 EST 2010

I missed one other one that you'll find handy.

voters.should have(2).items

Take a look at http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html because there's a lot of useful stuff...

On Feb 23, 2010, at 2:53 PM, Pete Hodgson wrote:

> Pat, Thanks for the response.
> On Feb 23, 1:43 pm, Pat Maddox <mailingli... at patmaddox.com> wrote:
>> I'm going to argue that your design is off, and then ignore the rest of your post :)
> Fair enough :) The 'design' in my example was made up on the spot to
> try and illustrate the kind of issues I've been coming up against
> without lots of irrelevant detail. I agree that the code has all sorts
> of silly issues.
>> Also, RSpec has two mechanisms for testing collections the way you want (so I guess I'm not ignoring your post after all).
> Thanks for pointing me towards the include and =~ matchers. This was
> part of what I was looking for, and would solve a lot of the issues
> I've hit in the past.
> That said, I still feel that it would be helpful to have some way of
> applying a matcher against the elements of a collection. I will just
> have to come up with a more plausible example... :)
> Cheers,
> Pete
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list