1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe UniformNotifier::Slack do
context 'not enabled' do
it 'should not notify slack' do
expect_any_instance_of(Slack::Notifier).to_not receive(:ping)
expect(UniformNotifier::Slack.out_of_channel_notify(title: 'notify slack')).to be_nil
end
end
context 'configuration' do
context 'no webhook_url is given' do
it 'should raise an error' do
expect { UniformNotifier.slack = {} }.to raise_error(UniformNotifier::NotificationError)
end
it 'should not notify slack' do
begin
UniformNotifier.slack = {}
rescue UniformNotifier::NotificationError
ensure
expect_any_instance_of(Slack::Notifier).to_not receive(:ping)
expect(UniformNotifier::Slack.out_of_channel_notify(title: 'notify slack')).to be_nil
end
end
end
it 'should remove invalid options' do
expect(Slack::Notifier).to receive(:new).with('http://some.slack.url', {}).and_return(true)
UniformNotifier.slack = { webhook_url: 'http://some.slack.url', pizza: 'pepperoni' }
expect(UniformNotifier::Slack.active?).to eq true
end
it 'should allow username and channel config options' do
expect(Slack::Notifier).to receive(:new)
.with('http://some.slack.url', { username: 'The Dude', channel: '#carpets' })
.and_return(true)
UniformNotifier.slack = { webhook_url: 'http://some.slack.url', username: 'The Dude', channel: '#carpets' }
expect(UniformNotifier::Slack.active?).to eq true
end
end
context 'properly configured' do
before(:example) do
@message = 'notify slack'
allow_any_instance_of(Slack::Notifier).to receive(:ping).and_return(@message)
end
it 'should notify slack' do
UniformNotifier.slack = { webhook_url: 'http://some.slack.url' }
expect_any_instance_of(Slack::Notifier).to receive(:ping)
expect(UniformNotifier::Slack.out_of_channel_notify(title: @message)).to eq @message
end
end
end
|