Skip to content

Instantly share code, notes, and snippets.

@stevo
Last active October 5, 2017 08:57
Show Gist options
  • Save stevo/22f40d69b3ab466bbf5feb713b35b279 to your computer and use it in GitHub Desktop.
Save stevo/22f40d69b3ab466bbf5feb713b35b279 to your computer and use it in GitHub Desktop.
Organizing stages of test
# 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