Skip to content

Instantly share code, notes, and snippets.

@bgswan
Last active December 24, 2015 15:19
Show Gist options
  • Save bgswan/6818814 to your computer and use it in GitHub Desktop.
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"
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
@orend
Copy link

orend commented Oct 9, 2013

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

@orend
Copy link

orend commented Oct 9, 2013

happy birthday btw!

@orend
Copy link

orend commented Oct 12, 2013

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