Commit ac8d1f74 authored by Justin Ho's avatar Justin Ho

Use shared examples for chat_notification_service_spec

parent 7f5fe388
......@@ -75,40 +75,27 @@ describe ChatNotificationService do
end
end
context 'with channel specified' do
let(:channel1) { 'slack-integration' }
let(:channel2) { '#slack-test' }
shared_examples 'with channel specified' do |channel, expected_channels|
before do
allow(chat_service).to receive(:push_channel).and_return(channel)
end
context 'with single channel name' do
let(:channel) { channel1 }
it 'notifies one channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1])).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: expected_channels)).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with multiple channel names' do
let(:channel) { [channel1, channel2].join(',') }
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1, channel2])).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with single channel specified' do
it_behaves_like 'with channel specified', 'slack-integration', ['slack-integration']
end
context 'with multiple channel names with spaces' do
let(:channel) { [channel1, channel2].join(', ') }
context 'with multiple channel names specified' do
it_behaves_like 'with channel specified', 'slack-integration,#slack-test', ['slack-integration', '#slack-test']
end
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1, channel2])).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with multiple channel names with spaces specified' do
it_behaves_like 'with channel specified', 'slack-integration, #slack-test, @UDLP91W0A', ['slack-integration', '#slack-test', '@UDLP91W0A']
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment