Created
June 13, 2013 21:14
-
-
Save mmmries/5777434 to your computer and use it in GitHub Desktop.
rspec test that a request makes certain changes to a model. How can I do something like this?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "my request" do | |
it "should update the model" do | |
Model.any_instance.should_receive(:save) do | |
self.changes.should include(:attribute) | |
self.attribute.should == 'value' | |
end | |
xhr :put, model_path(model), {attribute: 'value'} | |
end | |
end |
I like that a lot. Having a direct reference to the object means I can easily assert a lot of things.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, I would stub out the find call to the model and return an object that the test controls, then use an "expect to change" assertion on the attribute in question.