[rspec-users] Factories vs. stubs/mocks

Brennon Bortz brennon at brennonbortz.com
Mon Aug 30 11:59:50 EDT 2010

I am, as usual, assigning an instance variable in a controller's index action to find all instances of a model in the database.  I want to write a spec that checks that this variable is assigned correctly.  I can do:

it "should provide a collection of widgets in @widgets" do
      widget = Widget.create("title" => "my widget")
      get :index
      assigns[:widgets].should include(widget)


it "should provide a collection of widgets in @widgets" do
      widget = Factory.create(:widget)
      get :index
      assigns[:widgets].should include(widget)

Is there a better way to do this with a mock model, though?


Brennon Bortz
Software Researcher
Dundalk Institute of Technology
brennon.bortz at casala.ie
Ph.D. Researcher & Composer - Sonic Arts Research Centre
Queen's University, Belfast
brennon at brennonbortz.com / bbortz01 at qub.ac.uk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100830/f131fdac/attachment-0001.html>

More information about the rspec-users mailing list