[rspec-users] Checking that a controller created a separate model object
nick at deadorange.com
Mon Oct 13 22:03:58 EDT 2008
On 2008-10-13, at 17:14, O. Frabjous-Dey wrote:
> I thought some more about the issue and I think I'm approaching the
> problem the wrong way to begin with. As I understand it, part of
> the philosophy of RSpec is that using mocks and stubs when testing
> controllers and views instead of touching the database helps to keep
> each test context self-contained. So I really ought to be checking
> to see if Membership.create or or Membership.new is being called
> instead of examining the model object's relationships themselves -
> not that I can anyway, since it's a mock model.
> Can anyone confirm if that sounds right? If so, what method should
> I be using? #should_receive? Thanks again in advance.
Hi O. You're correct about using mocks and stubs to prevent hitting
the database. More importantly though, they allow you to test discrete
pieces of code without depending on the state of its surrounding code.
To spec the 'create' action, just go through it one "step" at a time.
describe "create" do
before :each do
@group = mock_model Group, :save => true
# somehow spec the assignment to flash[:notice]
it "should create a new group"
it "should respond to ..."
it "should save the group"
it "should assign the flash message"
it "should create a new Membership"
That doesn't seem complete. What'd I miss? =P
More information about the rspec-users