Sha256: ecfe9ad8f3c1616b094bd8025f2750c4d011a91125e694d48b91cbc1d25b28e0

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe PeertransferChat::Client do
  let(:slack_client) { instance_spy(Slack::Web::Client) }
  let(:team_channel) { 'a channel' }
  let(:team_username) { 'a username' }
  let(:api_token) { 'a_api_token' }

  context 'with class configuration' do
    before do
      PeertransferChat.configure do |c|
        c.channel = team_channel
        c.username = team_username
        c.api_token = api_token
      end

      allow(Slack::Web::Client).to receive(:new).
        with(token: api_token).
        and_return(slack_client)
    end

    describe '.speak' do
      it 'speaks something to a channel' do
        described_class.speak('hello')

        expect(slack_client).to have_received(:chat_postMessage).
          with(channel: team_channel, text: 'hello', as_user: true, username: team_username)

        PeertransferChat.reset!
      end
    end
  end

  context 'with instance configuration' do
    before do
      allow(Slack::Web::Client).to receive(:new).
        with(token: api_token).
        and_return(slack_client)
    end

    let(:client) do
      PeertransferChat::Client.new do |c|
        c.api_token = api_token
        c.channel = team_channel
        c.username = team_username
      end
    end

    describe '.speak' do
      it 'speaks something to a channel' do
        client.speak('hello')

        expect(slack_client).to have_received(:chat_postMessage).
          with(channel: team_channel, text: 'hello', as_user: true, username: team_username)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
peertransfer_chat-1.0.0 spec/integration/client_spec.rb