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

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

Pat Maddox wrote:
> Neil Cauldwell <lists at ruby-forum.com> writes:
>>>> ...so shouldn't the spec fail if we're returning all the users fixtures 
>>> which is true.  [1,2,3] is not an element of the array [1,2,3].  I used
>> description);
>> results
>> ...so I'm one step closer but I'm now a little confused by the other 
>> specs.
> They are different.  This is similar to the example I posted before:
> [].should include([])
> that will fail...
> [[]].should include([])
> will pass.  Do you see the difference?  One of them is an empty array,
> and one of them is an array containing a single element (which is itself
> an empty array).
> nil and [] are not equivalent in Ruby.
> Anyway, I'm pretty convinced that your stubbing isn't working at all.
> You can verify this by changing
> ThinkingSphinx::Search.stub!(:search).and_return(users)
> to
> ThinkingSphinx::Search.stub!(:search).and_raise("boom!")
> If your stubbed method is being called then it'll raise an error, but I
> suspect it's not.
> As far as the fixtures stuff, I'm afraid I can't help much there.  I
> think rails db fixtures are the devil and so have managed to put them
> completely out of my consciousness.
> Pat

I just tried the raise;



RSpec Results
36 examples, 5 failures
Finished in 1.338815 seconds

SearchesController handling GET /searches/people
should be successful

should render people template

I should have left my mac by now as my brain is pretty much fried by 
this of night, but, unless I'm mistaken, that means the stub is working, 

I would like to move away from fixtures but it'll have to wait for now. 
I just want to collect the users fixtures through the :people action in 
the searches controller and to make sure that a certain user fixture 
isn't among the return users...I didn't think it would so tricky! 
Thanks, though.
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list