Skip to content

Instantly share code, notes, and snippets.

@stevo
Last active October 6, 2017 10:00
Show Gist options
  • Save stevo/bac8b86c14bb3c80b94d95ae188e8dab to your computer and use it in GitHub Desktop.
Save stevo/bac8b86c14bb3c80b94d95ae188e8dab to your computer and use it in GitHub Desktop.
Focusing on descriptions
# Before - not clear what object / method do we test;
# not clear what is the expected behavior;
# context description is mixed with subject
describe "user form" do
describe "saving with phone number" do
it do
allow(SmsGateway).to receive(:send_message)
attributes = { phone_number: "0048 500 111 222" }
form = UserForm.new(User.new, attributes)
form.save
expect(SmsGateway).to have_received(:send_message).
with("0048 500 111 222", "Your account was created!")
end
end
end
# After - it is clear what method of which class we test,
# what is the context and what is the expected behavior
describe UserForm do
describe "#save" do
context "when persisting new user" do
context "when attributes contain valid phone number" do
it "delivers SMS account creation notification to user created" do
allow(SmsGateway).to receive(:send_message)
attributes = { phone_number: "0048 500 111 222" }
user = User.new
form = UserForm.new(user, attributes)
form.save
expect(SmsGateway).to have_received(:send_message).
with("0048 500 111 222", "Your account was created!")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment