Skip to content

Instantly share code, notes, and snippets.

@stevo
Created May 8, 2018 09:26
Show Gist options
  • Save stevo/1ca06922030b720495986528bab32909 to your computer and use it in GitHub Desktop.
Save stevo/1ca06922030b720495986528bab32909 to your computer and use it in GitHub Desktop.
An opinionated guide to readable RSpec (part 2 of 2)
context 'when notifications service is disabled' do
it 'does not create project deletion notification for user' do
api_user = create(:user, :api)
api_user_account = create(:account, user: api_user)
notifier_client = instance_double(NotifierClient)
allow(NotifierClient).to receive(:for).with(api_user_account) { notifier_client }
allow(notifier_client).to receive(:active?) { false }
user = create(:user)
project = create(:project, name: "Zebra", owner: user)
expect { DestroyProject.call(project) }.to_not change { Notification.count }
end
end
context 'when notifications service is active' do
it 'creates project deletion notification for user' do
api_user = create(:user, :api)
api_user_account = create(:account, user: api_user)
notifier_client = instance_double(NotifierClient)
allow(NotifierClient).to receive(:for).with(api_user_account) { notifier_client }
allow(notifier_client).to receive(:active?) { false }
user = create(:user)
project = create(:project, name: "Zebra", owner: user)
expect { DestroyProject.call(project) }.to change { Notification.count }.from(0).to(1)
expect(Notification.last).to have_attributes(
user: user,
text: 'Project Zebra has been removed'
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment