Sha256: 68034c9a31c5c36e94d23211c354c09d357f7fe0c9cb956aa0d03d74d83aec89

Contents?: true

Size: 1.98 KB

Versions: 18

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe Slack do
  let(:slack) { File.expand_path(File.join(__FILE__, '../../../bin/slack')) }
  before do
    @token = ENV.delete('SLACK_API_TOKEN')
  end
  after do
    ENV['SLACK_API_TOKEN'] = @token if @token
  end
  describe '#help' do
    it 'displays help' do
      help = `"#{slack}" help`
      expect(help).to include 'slack - Slack client.'
    end
  end
  context 'globals' do
    it 'enables request and response logging with -d' do
      output = `"#{slack}" --vcr-cassette-name=web/auth_test_success --slack-api-token=token -d auth test 2>&1`
      expect(output).to include 'post https://slack.com/api/auth.test'
      expect(output).to include 'Status: 200'
    end
    it 'requires --slack-api-token' do
      err = `"#{slack}" auth test 2>&1`
      expect(err).to start_with 'error: parse error: Set Slack API token via --slack-api-token or SLACK_API_TOKEN.'
    end
  end
  describe '#auth' do
    context 'bad auth' do
      it 'fails with an exception' do
        err = `"#{slack}" --vcr-cassette-name=web/auth_test_error --slack-api-token=token auth test 2>&1`
        expect(err).to eq "error: not_authed\n"
      end
    end
    context 'good auth' do
      it 'succeeds' do
        json = Slack::Messages::Message.new(JSON.parse(`"#{slack}" --vcr-cassette-name=web/auth_test_success --slack-api-token=token auth test 2>&1`))
        expect(json).to eq(
          'ok' => true,
          'url' => 'https://rubybot.slack.com/',
          'team' => 'team_name',
          'user' => 'user_name',
          'team_id' => 'TDEADBEEF',
          'user_id' => 'UBAADFOOD'
        )
        expect(json.ok).to be true
      end
    end
  end
  describe '#users' do
    it 'list' do
      json = Slack::Messages::Message.new(JSON.parse(`"#{slack}" --vcr-cassette-name=web/users_list --slack-api-token=token users list --presence=true 2>&1`))
      expect(json.ok).to be true
      expect(json.members.size).to eq 9
      expect(json.members.first['presence']).to eq 'away'
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
slack-ruby-client-0.11.1 spec/slack/slack_spec.rb
slack-ruby-client-0.11.0 spec/slack/slack_spec.rb
slack-ruby-client-0.10.0 spec/slack/slack_spec.rb
slack-ruby-client-0.9.1 spec/slack/slack_spec.rb
slack-ruby-client-0.9.0 spec/slack/slack_spec.rb
slack-ruby-client-0.8.1 spec/slack/slack_spec.rb
slack-ruby-client-0.8.0 spec/slack/slack_spec.rb
slack-ruby-client-0.7.9 spec/slack/slack_spec.rb
slack-ruby-client-0.7.8 spec/slack/slack_spec.rb
slack-ruby-client-0.7.7 spec/slack/slack_spec.rb
slack-ruby-client-0.7.6 spec/slack/slack_spec.rb
slack-ruby-client-0.7.5 spec/slack/slack_spec.rb
slack-ruby-client-0.7.4 spec/slack/slack_spec.rb
slack-ruby-client-0.7.3 spec/slack/slack_spec.rb
slack-ruby-client-0.7.2 spec/slack/slack_spec.rb
slack-ruby-client-0.7.1 spec/slack/slack_spec.rb
slack-ruby-client-0.7.0 spec/slack/slack_spec.rb
slack-ruby-client-0.6.0 spec/slack/slack_spec.rb