Marnen Laibow-Koser wrote in post #956174:
> Robert Walker wrote in post #956169:
>> Steve Ross wrote in post #956143:
>>> On Oct 20, 2010, at 11:34 PM, Ishit Parikh wrote:
>>>
>>>> I want test case in rspec for:
>>>> @drugs = Drug.where('drug_category_id = ?', params[:id])
>>
>> Assuming this line is in a controller action...
>
> ...then you shouldn't be writing RSpec specs for it at all.  Use
> Cucumber instead.

Agreed, but the OP asked about RSpec, so I showed an RSpec example.

> [...]
>> You don't need to hit the database just to make sure your controller is
>> assigning the @drugs instance variable. Use a mock instead.
>
> It's usually easier and more reliable to use a factory.  Yes, that hits
> the DB.  If you care that much, use an in-memory DB or something for
> testing.

Agreed, but was attempting to show "pure" RSpec rather than RSpec plus 
something else. Also, as you said using mocks can take more setup, but 
they can also provide a performance boost for specs that don't actually 
require hitting a database. I'll have to put some more thought in to 
using an in-memory database for testing. That's intriguing.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to