Created
May 8, 2018 09:26
-
-
Save stevo/1ca06922030b720495986528bab32909 to your computer and use it in GitHub Desktop.
An opinionated guide to readable RSpec (part 2 of 2)
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
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