[rspec-users] basic noob question

norm codehacker at comcast.net
Fri Jul 24 21:40:13 EDT 2009


I'm struggling mightily!

I have a controller called Govtpositions, and I'm just trying to test
the standard Rails 'create' method. So it seems as if three examples
would be appropriate... one to test the instantiation of the new model
from the params hash, another to test that it was saved, and then the
final redirection.

So just to test the model instantiation, I have:

describe GovtpositionsController, "POST govtpositions to create govt
new government position" do
  before do
    Govtposition.stub!(:new).and_return(@govtposition)
  end

  it "should create a new govt position model" do
    @govtposition = mock_model(Govtposition)
    @params = {"name"=>"chief"}
    Govtposition.should_receive(:new).with(@params).and_return
(@govtposition)
  end
end

But this example fails due to "Mock 'Govtposition_1001' received
unexpected message :save with (no args)"

Surely I should be able to test the save in a separate example, no? I
was expecting to declare just one expectation per example, with a
total of three for the create method. But the test failure seems to
suggest otherwise.

Any clarification you can offer would be much appreciated.


More information about the rspec-users mailing list