Last active
December 24, 2015 15:19
-
-
Save bgswan/6818814 to your computer and use it in GitHub Desktop.
Alternative version of test described here http://re-factor.com/blog/2013/09/27/slow-tests-are-the-symptom-not-the-cause/ using domain model rather than "service object"
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
describe MailingList do | |
let(:notifications) { double('notifications') } | |
let(:user) { User.new } | |
it 'registers a new user' do | |
expect(notifications).to receive(:call).with(user, 'list_name') | |
mailing_list = MailingList.new('list_name', notifications) | |
mailing_list.add(user) | |
expect(user.mailing_list_name).to eq('list_name') | |
end | |
end |
happy birthday btw!
One suggestion: I'd use a mock user and expect it to receive #add_to_mailing_list (a new method that's not coming from AR). See the tests here: orend/register@e0b9fd9 (from the post: "If we keep using our own methods instead of active record’s we’ve effectively made persistence and object lookup an implementation detail that’s the concern of the model only.")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey Brian, I replied to your comment here: http://re-factor.com/blog/2013/09/27/slow-tests-are-the-symptom-not-the-cause/#comment-1076628266 in case you didn't get a notification for it