[rspec-users] basic noob questions
BJ Clark
bj at aboutus.org
Sat Jul 25 00:45:38 EDT 2009
Norm,
I don't test instantiation and then saving, I test successful and
unsuccessful creation.
By testing this concern, I don't need to worry about expectations or
mocks, I actually create the object (or not!) and then test that the
controller behaves the way I expect it to in these situations.
Its probably not important that Govtpostion receives "new". It's
important that when it receives new with the proper things, and then
saves, that it behaves a certain way. And when it doesn't receive the
proper things, it acts another way.
Hope that helps,
BJ Clark
On Jul 24, 2009, at 5:13 PM, norm wrote:
> Struggling mightily!
>
> Testing a controller called Govtpositions. Just focusing on testing
> the create method for the moment. I would imagine there should be two
> examples for a successful save... instantiate the model object and
> then save it, is that right?
>
> So just to test the model object instantiation, I have:
>
> describe GovtpositionsController, 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
>
> This fails, with the reason that @govtposition is receiving an
> unexpected :save. Well I didn't intend to test save, I was planning to
> write another example for that assertion. Why can't I just test object
> creation in it's own example, must I also test saving in the same
> example? I'm clearly missing something basic!
>
> thanks in advance for any insight you can offer
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-----
BJ Clark
AboutUs.Org
More information about the rspec-users
mailing list