Last active
October 5, 2017 08:57
-
-
Save stevo/22f40d69b3ab466bbf5feb713b35b279 to your computer and use it in GitHub Desktop.
Organizing stages of 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
# Before: expectations are set before and after subject; | |
# whole code is in one chunk | |
describe UsersController do | |
describe "#create" do | |
it "uses UserForm to persist user" do | |
user = create(:user, name: "Mike") | |
expect(UserForm).to receive(:call).with(kind_of(User), name: "Tony") | |
put :update, params: { id: user.id, user: { name: "Tony" } } | |
expect(response).to be_ok | |
end | |
end | |
end | |
# After: expectations are set after calling subject; | |
# stages are separated with blank lines | |
describe UsersController do | |
describe "#update" do | |
it "uses UserForm to persist user" do | |
user = create(:user, name: "Mike") | |
allow(UserForm).to receive(:call).and_call_original | |
put :update, params: { id: user.id, user: { name: "Tony" } } | |
expect(response).to be_ok | |
expect(UserForm).to have_received(:call).with(kind_of(User), name: "Tony") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment