[rspec-users] how should i test this code with rspec

Pat Maddox pergesu at gmail.com
Mon Apr 7 11:08:00 EDT 2008

On Mon, Mar 24, 2008 at 3:24 AM, nathan.wu <cunheise at gmail.com> wrote:
> ids = Category.find(:all).map(&:id)
>  ids = mock('ids')
>  Category.should_receive(:find).with(all).and_return(??)
>  and
>  what's the difference between mock and mock_model
>  when should i use mock and mock_model

categories = [mock_model(Category, :id => 1), mock_model(Category, :id => 2)]
Category.should_receive(:find).with(:all).and_return categories

mock just creates a mock object for you.  mock_model makes it simulate
the class name you pass it, and creates a default unique ID.


More information about the rspec-users mailing list