Sha256: 51e5b38616f1f9c6eafc52ffc307788e0658c528fa3c7afeb890635cfade269d

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

describe Slack::Client do

  before do
    @client = auth_client
  end

  describe "#initialize" do
    it "requires team name" do
      expect { described_class.new(nil, nil) }.
        to raise_error ArgumentError, "Team name required"
    end

    it "requires token" do
      expect { described_class.new("foobar", nil) }.
        to raise_error ArgumentError, "Token required"
    end

    it "raises error on invalid team name" do
      names = ["foo bar", "foo $bar", "foo.bar"]

      names.each do |name|
        expect { described_class.new(name, "token") }.
          to raise_error "Invalid team name"
      end
    end
  end

  describe "#post_message", :vcr do
    it "posts a message to one channel" do
      result = @client.post_message("May the force be with you", "yoda-quotes")
      expect(result).to be true
      params = {text: "May the force be with you", channel: "#yoda-quotes", token: test_slack_token}
      assert_requested :post, slack_url_with_params("/chat.postMessage", params)
    end

    it "returns channel not found error" do
      expect{
        @client.post_message("May the force be with you", "channel-name")
      }.to raise_error(Slack::Error)

      params = {text: "May the force be with you", channel: "#channel-name", token: test_slack_token}
      assert_requested :post, slack_url_with_params("/chat.postMessage", params)
    end
  end

  describe "#channels", :vcr do
    it "returns all channels" do
      channels = @client.channels
      expect(channels).to be_kind_of Array
      assert_requested :get, auth_slack_url("/channels.list")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack.rb-0.0.3 spec/slack/client_spec.rb
slack.rb-0.0.2 spec/slack/client_spec.rb
slack.rb-0.0.1 spec/slack/client_spec.rb