Sha256: 87c8dc1794961f4edfb57215d80357e7ed6fa1c785ecfb335174ce907faa2213

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

# 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uniform_notifier-1.13.0 spec/uniform_notifier/slack_spec.rb
uniform_notifier-1.12.1 spec/uniform_notifier/slack_spec.rb
uniform_notifier-1.12.0 spec/uniform_notifier/slack_spec.rb