[rspec-users] New RSpec methods to Object proposal: should_all and should_none

David Chelimsky dchelimsky at gmail.com
Wed Dec 9 13:15:28 EST 2009


On Wed, Dec 9, 2009 at 11:55 AM, Pat Maddox <mailinglists at patmaddox.com> wrote:
> [@admin, @allowed_user].should all(be_allowed_to_visit(url))
> [@admin, @allowed_user].should all_be_allowed_to_visit(url)
> I prefer the first so as not to introduce more "magic" but if it catches on
> then moving to the second might be worthwhile.

Seems like there are a few approaches to syntax that might work, but
we also have to consider failure messages. Either of Pat's suggestions
would make it easier to provide a meaningful failure message.
Something like:

Expected <#User @role => 'admin'>, <#User @role => 'allowed'> to be
allowed to visit /some/path:
- <#User @role => 'allowed'> was not
- <#User @role => 'admin'> was

I'd like to see this developed outside rspec first, let a few ppl play
w/ different approaches. Once the idea has been fleshed out and in use
we can merge in the one that gets community consensus - or not :)

Cheers,
David

> Pat
> On Dec 9, 2009, at 5:27 AM, David Chelimsky wrote:
>
> On Wed, Dec 9, 2009 at 5:41 AM, Rodrigo Rosenfeld Rosas
> <lbocseg at yahoo.com.br> wrote:
>>
>> I was thinking that it would be great to add 2 additional methods to
>> Object: should_all and should_none.
>>
>> The idea is that we would be able to write tests like:
>>
>> [@admin, @allowed_user].should_all be_allowed_to_visit(url)
>>
>> [@unprivileged, @non_welcome].should_none be_allowed_to_visit(url)
>>
>> Implementation is trivial, but I think that tests would become much
>> cleaner than:
>>
>> [@admin, @allowed_user].each{|u| u.should be_allowed_to_visit(url)}
>>
>> Any thoughts on that?
>
> How about:
> each_of(@admin, @allowed_user).should be_allowed_to_visit(url)
> none_of(@admin, @allowed_user).should be_allowed_to_visit(url)
> This gets the cleanliness without adding to Object.
> WDYT?
> David
>
>>
>> Rodrigo.


More information about the rspec-users mailing list