slack-ruby-bot-bhe 0.5.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +17 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +58 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +81 -0
- data/CONTRIBUTING.md +139 -0
- data/DEPLOYMENT.md +33 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +263 -0
- data/RELEASING.md +67 -0
- data/Rakefile +19 -0
- data/TUTORIAL.md +205 -0
- data/UPGRADING.md +64 -0
- data/examples/minimal/Gemfile +3 -0
- data/examples/minimal/Procfile +1 -0
- data/examples/minimal/pongbot.rb +9 -0
- data/examples/weather/Gemfile +3 -0
- data/examples/weather/Procfile +1 -0
- data/examples/weather/weatherbot.rb +9 -0
- data/lib/config/application.rb +14 -0
- data/lib/config/boot.rb +8 -0
- data/lib/config/environment.rb +3 -0
- data/lib/initializers/giphy.rb +5 -0
- data/lib/slack-ruby-bot.rb +25 -0
- data/lib/slack-ruby-bot/about.rb +7 -0
- data/lib/slack-ruby-bot/app.rb +46 -0
- data/lib/slack-ruby-bot/bot.rb +7 -0
- data/lib/slack-ruby-bot/client.rb +44 -0
- data/lib/slack-ruby-bot/commands.rb +5 -0
- data/lib/slack-ruby-bot/commands/about.rb +12 -0
- data/lib/slack-ruby-bot/commands/base.rb +121 -0
- data/lib/slack-ruby-bot/commands/help.rb +9 -0
- data/lib/slack-ruby-bot/commands/hi.rb +9 -0
- data/lib/slack-ruby-bot/commands/unknown.rb +11 -0
- data/lib/slack-ruby-bot/config.rb +40 -0
- data/lib/slack-ruby-bot/hooks.rb +3 -0
- data/lib/slack-ruby-bot/hooks/base.rb +10 -0
- data/lib/slack-ruby-bot/hooks/hello.rb +11 -0
- data/lib/slack-ruby-bot/hooks/message.rb +50 -0
- data/lib/slack-ruby-bot/rspec.rb +12 -0
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml +16 -0
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/migration_in_progress.yml +30 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +27 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +30 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +19 -0
- data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +5 -0
- data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +9 -0
- data/lib/slack-ruby-bot/rspec/support/vcr.rb +8 -0
- data/lib/slack-ruby-bot/server.rb +111 -0
- data/lib/slack-ruby-bot/version.rb +3 -0
- data/lib/slack_ruby_bot.rb +1 -0
- data/screenshots/aliases.gif +0 -0
- data/screenshots/demo.gif +0 -0
- data/screenshots/dms.gif +0 -0
- data/screenshots/register-bot.png +0 -0
- data/screenshots/weather.gif +0 -0
- data/slack-ruby-bot.gemspec +28 -0
- data/slack.png +0 -0
- data/spec/slack-ruby-bot/app_spec.rb +15 -0
- data/spec/slack-ruby-bot/commands/about_spec.rb +19 -0
- data/spec/slack-ruby-bot/commands/aliases_spec.rb +22 -0
- data/spec/slack-ruby-bot/commands/bot_spec.rb +19 -0
- data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +22 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +17 -0
- data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +20 -0
- data/spec/slack-ruby-bot/commands/commands_spec.rb +21 -0
- data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +23 -0
- data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +38 -0
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +22 -0
- data/spec/slack-ruby-bot/commands/help_spec.rb +10 -0
- data/spec/slack-ruby-bot/commands/hi_spec.rb +19 -0
- data/spec/slack-ruby-bot/commands/match_spec.rb +17 -0
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +34 -0
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +22 -0
- data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +15 -0
- data/spec/slack-ruby-bot/commands/operators_spec.rb +20 -0
- data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +23 -0
- data/spec/slack-ruby-bot/commands/send_gif_spec.rb +32 -0
- data/spec/slack-ruby-bot/commands/send_message_spec.rb +19 -0
- data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +73 -0
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +18 -0
- data/spec/slack-ruby-bot/config_spec.rb +55 -0
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +19 -0
- data/spec/slack-ruby-bot/server_spec.rb +73 -0
- data/spec/slack-ruby-bot/version_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- metadata +313 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot do
|
|
4
|
+
def app
|
|
5
|
+
SlackRubyBot::App.new
|
|
6
|
+
end
|
|
7
|
+
context 'it responds to direct messages' do
|
|
8
|
+
it 'with bot name' do
|
|
9
|
+
expect(message: "#{SlackRubyBot.config.user} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
|
|
10
|
+
end
|
|
11
|
+
it 'with bot name capitalized' do
|
|
12
|
+
expect(message: "#{SlackRubyBot.config.user.upcase} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
|
|
13
|
+
end
|
|
14
|
+
it 'with bot user id' do
|
|
15
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}> hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
|
|
16
|
+
end
|
|
17
|
+
it 'without bot name' do
|
|
18
|
+
expect(message: 'hi', channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
context 'it responds to direct name calling' do
|
|
22
|
+
it 'with bot name' do
|
|
23
|
+
expect(message: "#{SlackRubyBot.config.user}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
|
|
24
|
+
end
|
|
25
|
+
it 'with bot name capitalized' do
|
|
26
|
+
expect(message: "#{SlackRubyBot.config.user.upcase}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
|
|
27
|
+
end
|
|
28
|
+
it 'with bot user id' do
|
|
29
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}>", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
|
|
30
|
+
end
|
|
31
|
+
it 'with bot user id and a colon' do
|
|
32
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}>:", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
|
|
33
|
+
end
|
|
34
|
+
it 'with bot user id and a colon and a space' do
|
|
35
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}>: ", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'empty_text'
|
|
7
|
+
|
|
8
|
+
def self.call(client, data, _match)
|
|
9
|
+
send_message client, data.channel, nil
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
def app
|
|
14
|
+
SlackRubyBot::App.new
|
|
15
|
+
end
|
|
16
|
+
let(:client) { app.send(:client) }
|
|
17
|
+
it 'sends default text' do
|
|
18
|
+
allow(Giphy).to receive(:random)
|
|
19
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_message_with_gif).with(client, 'channel', 'Nothing to see here.', 'nothing', {})
|
|
20
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands::Help do
|
|
4
|
+
def app
|
|
5
|
+
SlackRubyBot::App.new
|
|
6
|
+
end
|
|
7
|
+
it 'help' do
|
|
8
|
+
expect(message: "#{SlackRubyBot.config.user} help").to respond_with_slack_message('See https://github.com/dblock/slack-ruby-bot, please.')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands::Hi do
|
|
4
|
+
def app
|
|
5
|
+
SlackRubyBot::App.new
|
|
6
|
+
end
|
|
7
|
+
it 'says hi' do
|
|
8
|
+
expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message('Hi <@user>!')
|
|
9
|
+
end
|
|
10
|
+
it 'says hi to bot:' do
|
|
11
|
+
expect(message: "#{SlackRubyBot.config.user}: hi").to respond_with_slack_message('Hi <@user>!')
|
|
12
|
+
end
|
|
13
|
+
it 'says hi to @bot' do
|
|
14
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}> hi").to respond_with_slack_message('Hi <@user>!')
|
|
15
|
+
end
|
|
16
|
+
it 'says hi to @bot: ' do
|
|
17
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}>: hi").to respond_with_slack_message('Hi <@user>!')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
match(/^Reticulate (?<spline_name>\w*)$/) do |client, data, match|
|
|
7
|
+
send_message client, data.channel, "Reticulated #{match[:spline_name]}."
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
def app
|
|
12
|
+
SlackRubyBot::App.new
|
|
13
|
+
end
|
|
14
|
+
it 'matches' do
|
|
15
|
+
expect(message: 'Reticulate spline').to respond_with_slack_message('Reticulated spline.')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::App do
|
|
4
|
+
def app
|
|
5
|
+
SlackRubyBot::App.new
|
|
6
|
+
end
|
|
7
|
+
let(:client) { subject.send(:client) }
|
|
8
|
+
before do
|
|
9
|
+
allow(client).to receive(:self).and_return('id' => 'UDEADBEEF')
|
|
10
|
+
allow(Giphy).to receive(:random)
|
|
11
|
+
end
|
|
12
|
+
context 'default' do
|
|
13
|
+
it 'does not respond to self' do
|
|
14
|
+
expect(SlackRubyBot::Commands::Base).to_not receive(:send_client_message)
|
|
15
|
+
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
context 'with allow_message_loops=true' do
|
|
19
|
+
before do
|
|
20
|
+
SlackRubyBot.configure do |config|
|
|
21
|
+
config.allow_message_loops = true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
after do
|
|
25
|
+
SlackRubyBot.configure do |config|
|
|
26
|
+
config.allow_message_loops = nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
it 'responds to self' do
|
|
30
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message)
|
|
31
|
+
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'nil_text'
|
|
7
|
+
|
|
8
|
+
def self.call(_client, data, _match)
|
|
9
|
+
send_message cilent, data.channel, nil
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
def app
|
|
14
|
+
SlackRubyBot::App.new
|
|
15
|
+
end
|
|
16
|
+
let(:client) { app.send(:client) }
|
|
17
|
+
it 'ignores nil messages' do
|
|
18
|
+
allow(Giphy).to receive(:random)
|
|
19
|
+
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message_with_gif)
|
|
20
|
+
app.send(:message, client, text: nil, channel: 'channel', user: 'user')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands::Base do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'not_implemented'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
def app
|
|
10
|
+
SlackRubyBot::App.new
|
|
11
|
+
end
|
|
12
|
+
it 'raises not implemented' do
|
|
13
|
+
expect(message: "#{SlackRubyBot.config.user} not_implemented").to respond_with_error(NotImplementedError, 'rubybot not_implemented')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
operator '='
|
|
7
|
+
operator '-'
|
|
8
|
+
|
|
9
|
+
def self.call(client, data, match)
|
|
10
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
def app
|
|
15
|
+
SlackRubyBot::App.new
|
|
16
|
+
end
|
|
17
|
+
it 'supports operators' do
|
|
18
|
+
expect(message: '=2+2').to respond_with_slack_message('=: 2+2')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
operator '=' do |client, data, match|
|
|
7
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
operator '+', '-' do |client, data, match|
|
|
11
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
def app
|
|
16
|
+
SlackRubyBot::App.new
|
|
17
|
+
end
|
|
18
|
+
it 'supports operator blocks' do
|
|
19
|
+
expect(message: '=2+2').to respond_with_slack_message('=: 2+2')
|
|
20
|
+
expect(message: '+2+2').to respond_with_slack_message('+: 2+2')
|
|
21
|
+
expect(message: '-2+2').to respond_with_slack_message('-: 2+2')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'send_gif_spec' do |client, data, _match|
|
|
7
|
+
send_gif client, data.channel, 'dummy'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
def app
|
|
12
|
+
SlackRubyBot::App.new
|
|
13
|
+
end
|
|
14
|
+
let(:client) { app.send(:client) }
|
|
15
|
+
let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' }
|
|
16
|
+
it 'sends a gif' do
|
|
17
|
+
gif = Giphy::RandomGif.new('image_url' => gif_image_url)
|
|
18
|
+
expect(Giphy).to receive(:random).and_return(gif)
|
|
19
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: gif_image_url)
|
|
20
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
|
21
|
+
end
|
|
22
|
+
it 'eats up the error' do
|
|
23
|
+
expect(Giphy).to receive(:random) { fail 'oh no!' }
|
|
24
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
|
|
25
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
|
26
|
+
end
|
|
27
|
+
it 'eats up nil gif' do
|
|
28
|
+
expect(Giphy).to receive(:random).and_return(nil)
|
|
29
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
|
|
30
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'send_message_spec' do |client, data, match|
|
|
7
|
+
send_message client, data.channel, match['expression']
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
def app
|
|
12
|
+
SlackRubyBot::App.new
|
|
13
|
+
end
|
|
14
|
+
let(:client) { app.send(:client) }
|
|
15
|
+
it 'sends a message' do
|
|
16
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
17
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'send_message_with_gif_spec' do |client, data, match|
|
|
7
|
+
send_message_with_gif client, data.channel, match['expression'], 'dummy'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
def app
|
|
12
|
+
SlackRubyBot::App.new
|
|
13
|
+
end
|
|
14
|
+
let(:client) { app.send(:client) }
|
|
15
|
+
let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' }
|
|
16
|
+
it 'sends a message with gif' do
|
|
17
|
+
gif = Giphy::RandomGif.new('image_url' => gif_image_url)
|
|
18
|
+
expect(Giphy).to receive(:random).and_return(gif)
|
|
19
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: "message\n#{gif_image_url}")
|
|
20
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
21
|
+
end
|
|
22
|
+
it 'eats up the error' do
|
|
23
|
+
expect(Giphy).to receive(:random) { fail 'oh no!' }
|
|
24
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
25
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
26
|
+
end
|
|
27
|
+
it 'eats up nil gif' do
|
|
28
|
+
expect(Giphy).to receive(:random).and_return(nil)
|
|
29
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
30
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
31
|
+
end
|
|
32
|
+
context 'send_gifs' do
|
|
33
|
+
context 'set to false via client' do
|
|
34
|
+
before do
|
|
35
|
+
client.send_gifs = false
|
|
36
|
+
end
|
|
37
|
+
it 'does not send a gif' do
|
|
38
|
+
expect(Giphy).to_not receive(:random)
|
|
39
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
40
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
41
|
+
end
|
|
42
|
+
after do
|
|
43
|
+
client.send_gifs = true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
context 'set to false via config' do
|
|
47
|
+
before do
|
|
48
|
+
SlackRubyBot::Config.send_gifs = false
|
|
49
|
+
end
|
|
50
|
+
it 'does not send a gif' do
|
|
51
|
+
expect(Giphy).to_not receive(:random)
|
|
52
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
53
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
54
|
+
end
|
|
55
|
+
after do
|
|
56
|
+
SlackRubyBot::Config.send_gifs = nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
context 'set to false via SLACK_RUBY_BOT_SEND_GIFS' do
|
|
60
|
+
before do
|
|
61
|
+
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
|
|
62
|
+
end
|
|
63
|
+
it 'does not send a gif' do
|
|
64
|
+
expect(Giphy).to_not receive(:random)
|
|
65
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
|
66
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
|
67
|
+
end
|
|
68
|
+
after do
|
|
69
|
+
ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS'
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Commands::Unknown do
|
|
4
|
+
def app
|
|
5
|
+
SlackRubyBot::App.new
|
|
6
|
+
end
|
|
7
|
+
let(:client) { app.send(:client) }
|
|
8
|
+
it 'invalid command' do
|
|
9
|
+
expect(message: "#{SlackRubyBot.config.user} foobar").to respond_with_slack_message("Sorry <@user>, I don't understand that command!")
|
|
10
|
+
end
|
|
11
|
+
it 'invalid command with @bot:' do
|
|
12
|
+
expect(message: "<@#{SlackRubyBot.config.user_id}>: foobar").to respond_with_slack_message("Sorry <@user>, I don't understand that command!")
|
|
13
|
+
end
|
|
14
|
+
it 'does not respond to sad face' do
|
|
15
|
+
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message)
|
|
16
|
+
SlackRubyBot::App.new.send(:message, client, text: ':((')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SlackRubyBot::Config do
|
|
4
|
+
context 'send_gifs?' do
|
|
5
|
+
context 'default' do
|
|
6
|
+
it 'is true' do
|
|
7
|
+
expect(SlackRubyBot::Config.send_gifs?).to be true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
context 'set to false' do
|
|
11
|
+
before do
|
|
12
|
+
SlackRubyBot::Config.send_gifs = false
|
|
13
|
+
end
|
|
14
|
+
it 'is false' do
|
|
15
|
+
expect(SlackRubyBot::Config.send_gifs?).to be false
|
|
16
|
+
end
|
|
17
|
+
after do
|
|
18
|
+
SlackRubyBot::Config.send_gifs = nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
context 'set to false via SLACK_RUBY_BOT_SEND_GIFS' do
|
|
22
|
+
before do
|
|
23
|
+
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
|
|
24
|
+
end
|
|
25
|
+
it 'is false' do
|
|
26
|
+
expect(SlackRubyBot::Config.send_gifs?).to be false
|
|
27
|
+
end
|
|
28
|
+
after do
|
|
29
|
+
ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
context 'set to true' do
|
|
33
|
+
before do
|
|
34
|
+
SlackRubyBot::Config.send_gifs = true
|
|
35
|
+
end
|
|
36
|
+
it 'is false' do
|
|
37
|
+
expect(SlackRubyBot::Config.send_gifs?).to be true
|
|
38
|
+
end
|
|
39
|
+
after do
|
|
40
|
+
SlackRubyBot::Config.send_gifs = nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
context 'set to true via SLACK_RUBY_BOT_SEND_GIFS' do
|
|
44
|
+
before do
|
|
45
|
+
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
|
|
46
|
+
end
|
|
47
|
+
it 'is false' do
|
|
48
|
+
expect(SlackRubyBot::Config.send_gifs?).to be true
|
|
49
|
+
end
|
|
50
|
+
after do
|
|
51
|
+
ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe RSpec do
|
|
4
|
+
let! :command do
|
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
|
6
|
+
command 'raise'
|
|
7
|
+
|
|
8
|
+
def self.call(_client, _data, match)
|
|
9
|
+
fail ArgumentError, match[:command]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
def app
|
|
14
|
+
SlackRubyBot::App.new
|
|
15
|
+
end
|
|
16
|
+
it 'respond_with_error' do
|
|
17
|
+
expect(message: "#{SlackRubyBot.config.user} raise").to respond_with_error(ArgumentError, 'raise')
|
|
18
|
+
end
|
|
19
|
+
end
|