Created
December 31, 2010 15:52
-
-
Save bgswan/761102 to your computer and use it in GitHub Desktop.
Mock style test versus non mock test
This file contains hidden or 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
# common use of mocks in a Rails app | |
it "updates the requested book" do | |
mock_book = mock(:book) | |
Book.should_receive(:find).with("37").and_return(mock_book) | |
mock_book.should_receive(:update_attributes).with({:these => 'params'}) | |
put :update, :id => "37", :book => {:these => 'params'} | |
end | |
# without mocks a more readable, less brittle test | |
it "updates the requested book" do | |
a_book = Book.create(:author => 'an author') | |
put :update, :id => a_book.to_param, :book => {:author => 'JR Hartley'} | |
assert_equal 'JR Hartley', a_book.author | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment