Last active
October 6, 2017 10:00
-
-
Save stevo/bac8b86c14bb3c80b94d95ae188e8dab to your computer and use it in GitHub Desktop.
Focusing on descriptions
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 - 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