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

Scott Taylor mailing_lists at railsnewbie.com
Thu Oct 4 13:31:06 EDT 2007


On Oct 4, 2007, at 12:46 PM, Nick Sieger wrote:

> On 10/4/07, Eric Pugh <epugh at opensourceconnections.com> wrote:
>> Hi all,
>>
>> I have an array of shipping_type's being returned, and I want to see
>> what is in there.  In the past I have done:
>>
>>      shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should  
>> be_true
>>
>> This works, but looks really ugly..  It just doesn't roll of the
>> tongue very well.  I then looked up the use of Predicates, which I
>> had been using, but hadn't realized:
>>
>>      shipping_type.should be_include(Cart::SHIPPING_TYPE_REGULAR)
>
> You were close on this one, it should just be
>
> shipping_type.should include(Cart::SHIPPING_TYPE_REGULAR)
>
> It's a special predicate just for working with arrays.

Isn't it a general predicate for all foo? (boolean) methods?

class Object
	def foo?
	 true
	end
end

Object.new.should be_foo

Doesn't that work, as well?

Scott





More information about the rspec-users mailing list