[rspec-users] Using Predicates to look at an array..

David Chelimsky dchelimsky at gmail.com
Thu Oct 4 13:23:05 EDT 2007

On 10/4/07, Geoffrey Wiseman <geoffrey.wiseman at gmail.com> wrote:
> On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote:
> >      shipping_type.should
> be_include(Cart::SHIPPING_TYPE_REGULAR)
> This is what I usually do; I agree the syntax of be_include looks odd, as is
> true for some other predicates.
> OTOH,  it's hard to find a formulation that works well for all predicates.
> For instance:
>   domain.should_valid doesn't look as good as domain.should be_valid
>   domain.should_include(x) looks better than domain.should be_include(x)
> Rspec could support both, which means you could select the one that "looks"
> right, I guess.  That might lead to inconsistent usage.  I can live with the
> current approach as well, looks odd, but it's not a serious problem for me.

As Nick points out in this thread, rspec supports:

collection.should include(some_item)

Also, you can define your own predicate matchers very easily using the
predicate_matchers collection:

predicate_matchers[:be_able_to_cook] = [:can_cook?]

chef.should be_able_to_cook
=> passes if chef.can_cook?


>   - Geoffrey
> --
> Geoffrey Wiseman
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list