[rspec-users] Spec for 'an array should not include an item'

Neil Cauldwell lists at ruby-forum.com
Wed Oct 1 15:17:30 EDT 2008


Pat Maddox wrote:
> Neil Cauldwell <lists at ruby-forum.com> writes:
> 
>>> 
>> (which it doesn't, therefore suggesting the spec is broken);
>>    def do_get
>>      ThinkingSphinx::Search.stub!(:search).and_return(users)
>>      get :people, :search => "bob"
>>    end
>>
>> ...so shouldn't the spec fail if we're returning all the users fixtures 
>> when assigns[:results].should_not include(users)?
>>
>> Thanks
> 
> Well, flip the should_not to should and it ought to fail, and give you a
> bit more info.  Or print the stuff out.  I imagine what's ultimately
> happening is something along the lines of
> 
> [1,2,3].should_not include([1,2,3])
> 
> which is true.  [1,2,3] is not an element of the array [1,2,3].  I used
> a simplified example here but it applies equally to an array of User
> objects.
> 
> Anyway, what kind of debugging have you done to see what objects you're
> actually dealing with?  I think doing "p assigns[:results]" and "p
> users" will help point you in the right direction...
> 
> Pat

Thanks Pat. That really helps. If I do the flip (please ignore the spec 
description);

it "should not include any inactive users in an assigned array of user 
results " do
  do_get
  assigns[:results].should include(users)
end

Rspec tells me;

should not include any inactive users in an assigned array of user 
results
expected [] to include []

I was expecting :results to contain something, otherwise, wouldn't this 
spec fail (?), or is nil different to empty?;

   it "should assign an array of user results" do
     do_get
     assigns[:results].should_not be_nil
   end

...so I'm one step closer but I'm now a little confused by the other 
specs.

I haven't done any debugging, I haven't come across any debugging 
techniques within Rspec before - please treat me as an absolute newbie 
to this.
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list