[rspec-users] Testing Controller 'show' action

David Chelimsky dchelimsky at gmail.com
Thu Nov 18 08:19:26 EST 2010

On Nov 17, 2010, at 2:16 PM, Andrew Davis wrote:

> Hello, I'm still pretty new to Rails, and I've used rspec on all of my
> models with success.


> Now I'm working on the controllers, but I'm having
> difficulty. Everything I try is giving me a response of false,

Please post backtraces when you have failures. "response of false" could mean too many different things.

> and I was
> hoping to get some insight from this community.
> All code can be viewed in this pastie:
> http://pastie.org/private/rn7vhzvmamn9tuytuuqq

Not sure if it's related, but I notice this line in the pastie:

  TaskOrder.stub!(:find, @task_order.id).and_return(@task_order)

This is incorrect usage of stub. If you're trying to constraint the stub to the id, you have to use the "with" method, which would also need something to account for the hash with :include => "criteria":

  TaskOrder.stub!(:find).with(@task_order.id, anything).and_return(@task_order)

The "anything" method is an argument matcher that will match against anything passed in. If you want to be specific about the hash as well, you could do this:

  TaskOrder.stub(:find).with(@task_order.id, "include" => "criteria").and_return(@task_order)

But I'd recommend against this level of detail and stick to either "anything" or perhaps defining a named scope or a wrapper method for including the criteria:


I don't really like the name "find_with_criteria" but hopefully you'll come up with something better :)


> Please let me know if you need anything else!
> Thanks in advance!
> Andrew Davis

More information about the rspec-users mailing list