[rspec-devel] [ rspec-Feature Requests-9304 ] should_all < predicate>
noreply at rubyforge.org
noreply at rubyforge.org
Wed Apr 4 00:51:21 EDT 2007
Feature Requests item #9304, was opened at 2007-03-15 14:58
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=9304&group_id=797
Category: expectation module
Group: None
Status: Open
>Priority: 2
Submitted By: Chris Hoffman (hoffman_c)
Assigned to: Nobody (None)
Summary: should_all <predicate>
Initial Comment:
Hello,
In order to check the properties of each element in a collection, one must presently do the following (as far as I can tell):
mycollection = [2,3,5,7]
mycollection.each { |num| num.should_be_prime }
I suggest an improvement that would significantly increase the readability of these statement types:
mycollection.should_all be_prime
Keep up the good work! This software has made me into a better programmer.
----------------------------------------------------------------------
>Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-04 04:51
Message:
Actually, you're original idea would be more flexible, though I think #should_each would be more ruby-ish:
(1..10).should_each be < 11
While it does look pretty sweet, I'm not 100% sold on the real value of this yet. We've just taken great pains to un-pollute Object so I'm hesitant to add anything else to it.
There are also some questions that come up like whether to add #should_each_not, or whether to fail on the first iteration that fails or collect them all. This could get quite a bit more complicated.
All of that said, you can add this to your spec_helper and get the functionality you're looking for in the mean time.
class Object
def should_each(*args)
each {|item| item.should(*args)}
end
end
Cheers,
David
----------------------------------------------------------------------
Comment By: Chris Hoffman (hoffman_c)
Date: 2007-03-15 15:14
Message:
Sure, that will work; I'm not intimate with your code base,
so whatever you think is best as far as implementation would
be great.
----------------------------------------------------------------------
Comment By: David Chelimsky (dchelimsky)
Date: 2007-03-15 15:11
Message:
How about:
mycollection.should all_be_prime
Then we don't further pollute Object.
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=9304&group_id=797
More information about the rspec-devel
mailing list