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

Pat Maddox pergesu at gmail.com
Wed Oct 1 12:10:03 EDT 2008

Neil Cauldwell <lists at ruby-forum.com> writes:

> Pat Maddox wrote:
>> Neil Cauldwell <lists at ruby-forum.com> writes:
>>>     respond_to do |format|
>>>       format.html
>>>       format.xml  { render :xml => @results }
>>>     end
>>>   end
>>> Cheers
>> You're stubbing User.search, but you don't actually call it.  search
>> ends up being called on a named_scope collection proxy.  So I think that
>> this is using the real implementation of both active and search.
>> I never saw you post a failure message, so I'm not actually sure what
>> problem you're having.  A failure message would be helpful.
>> Pat
> Pat, I don't see an error message but, I was expecting this to fail 
> (which it doesn't, therefore suggesting the spec is broken);
> it "should not include any inactive users in an assigned array of user 
> results " do
>   do_get
>   assigns[:results].should_not include(users)
> end
> I was under the assumption that the above spec checks that we don't have 
> any of the users fixtures in the :results. The spec uses this;
>    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

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...


More information about the rspec-users mailing list