share_worker_spec: get rid of `should` expectation syntax
This commit is contained in:
parent
96ccb09908
commit
7ccad7bfab
|
@ -23,40 +23,44 @@ describe ShareWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#perform" do
|
describe "#perform" do
|
||||||
subject {
|
before do
|
||||||
|
allow(Sidekiq.logger).to receive(:info)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject do
|
||||||
Sidekiq::Testing.fake! do
|
Sidekiq::Testing.fake! do
|
||||||
ShareWorker.perform_async(user.id, answer.id, 'twitter')
|
ShareWorker.perform_async(user.id, answer.id, 'twitter')
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
context 'when answer doesn\'t exist' do
|
context 'when answer doesn\'t exist' do
|
||||||
it 'prevents the job from retrying and logs a message' do
|
it 'prevents the job from retrying and logs a message' do
|
||||||
answer.destroy!
|
answer.destroy!
|
||||||
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} for user ##{user.id} to Twitter but the user/answer/service did not exist (likely deleted), will not retry.")
|
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
||||||
|
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} for user ##{user.id} to Twitter but the user/answer/service did not exist (likely deleted), will not retry.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when answer exists' do
|
context 'when answer exists' do
|
||||||
it 'handles Twitter::Error::DuplicateStatus' do
|
it 'handles Twitter::Error::DuplicateStatus' do
|
||||||
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::DuplicateStatus)
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::DuplicateStatus)
|
||||||
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the status was already posted.")
|
|
||||||
subject
|
subject
|
||||||
ShareWorker.drain
|
ShareWorker.drain
|
||||||
|
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the status was already posted.")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles Twitter::Error::Unauthorized' do
|
it 'handles Twitter::Error::Unauthorized' do
|
||||||
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Unauthorized)
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Unauthorized)
|
||||||
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
|
||||||
subject
|
subject
|
||||||
ShareWorker.drain
|
ShareWorker.drain
|
||||||
|
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retries on unhandled exceptions' do
|
it 'retries on unhandled exceptions' do
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
Sidekiq.logger.should_receive(:info)
|
|
||||||
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
||||||
|
expect(Sidekiq.logger).to have_received(:info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue