slack-ruby-bot 0.11.2 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +14 -1
- data/.rubocop_todo.yml +14 -42
- data/.travis.yml +11 -13
- data/CHANGELOG.md +39 -6
- data/CONTRIBUTING.md +5 -1
- data/DEPLOYMENT.md +63 -9
- data/Dangerfile +4 -0
- data/Gemfile +11 -7
- data/LICENSE.md +1 -1
- data/MIGRATION.md +13 -0
- data/README.md +133 -65
- data/Rakefile +2 -0
- data/TUTORIAL.md +23 -0
- data/UPGRADING.md +50 -0
- data/examples/inventory/Gemfile +2 -0
- data/examples/inventory/inventorybot.rb +5 -1
- data/examples/market/Gemfile +4 -3
- data/examples/market/marketbot.rb +22 -15
- data/examples/minimal/Gemfile +3 -1
- data/examples/minimal/pongbot.rb +2 -0
- data/examples/weather/Gemfile +2 -0
- data/examples/weather/weatherbot.rb +2 -0
- data/lib/config/application.rb +4 -2
- data/lib/config/boot.rb +2 -0
- data/lib/config/environment.rb +3 -1
- data/lib/slack-ruby-bot.rb +3 -1
- data/lib/slack-ruby-bot/about.rb +3 -1
- data/lib/slack-ruby-bot/app.rb +18 -12
- data/lib/slack-ruby-bot/bot.rb +3 -1
- data/lib/slack-ruby-bot/client.rb +25 -23
- data/lib/slack-ruby-bot/commands.rb +2 -0
- data/lib/slack-ruby-bot/commands/about.rb +3 -1
- data/lib/slack-ruby-bot/commands/base.rb +13 -21
- data/lib/slack-ruby-bot/commands/help.rb +10 -8
- data/lib/slack-ruby-bot/commands/hi.rb +3 -1
- data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
- data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
- data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
- data/lib/slack-ruby-bot/commands/unknown.rb +3 -1
- data/lib/slack-ruby-bot/config.rb +7 -7
- data/lib/slack-ruby-bot/hooks.rb +2 -0
- data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
- data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -6
- data/lib/slack-ruby-bot/hooks/message.rb +11 -10
- data/lib/slack-ruby-bot/hooks/set.rb +3 -1
- data/lib/slack-ruby-bot/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
- data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
- data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
- data/lib/slack-ruby-bot/rspec.rb +3 -1
- data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +4 -1
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -7
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +15 -14
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +26 -19
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
- data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +3 -1
- data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
- data/lib/slack-ruby-bot/server.rb +5 -28
- data/lib/slack-ruby-bot/support/loggable.rb +2 -0
- data/lib/slack-ruby-bot/version.rb +3 -1
- data/lib/slack_ruby_bot.rb +2 -0
- data/screenshots/create-classic-app.png +0 -0
- data/slack-ruby-bot.gemspec +6 -3
- data/spec/slack-ruby-bot/app_spec.rb +64 -1
- data/spec/slack-ruby-bot/client_spec.rb +103 -28
- data/spec/slack-ruby-bot/commands/about_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/aliases_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/attachment_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_messages_spec.rb +26 -0
- data/spec/slack-ruby-bot/commands/bot_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
- data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/non_breaking_space_spec.rb +29 -0
- data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/attrs_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/help_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -0
- data/spec/slack-ruby-bot/config_spec.rb +2 -57
- data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
- data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -5
- data/spec/slack-ruby-bot/hooks/message_spec.rb +8 -35
- data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
- data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
- data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
- data/spec/slack-ruby-bot/server_spec.rb +6 -33
- data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
- data/spec/slack-ruby-bot/version_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -6
- data/{lib/slack-ruby-bot/rspec → spec}/support/fixtures/slack/migration_in_progress.yml +0 -0
- data/{lib/slack-ruby-bot/rspec → spec}/support/vcr.rb +2 -0
- metadata +28 -29
- data/lib/initializers/giphy.rb +0 -8
- data/lib/initializers/giphy_client.rb +0 -39
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_burrito.yml +0 -69
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito.yml +0 -71
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito_rated_y.yml +0 -71
- data/screenshots/register-bot.png +0 -0
- data/spec/slack-ruby-bot/commands/send_gif_spec.rb +0 -25
- data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +0 -38
- data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +0 -28
- data/spec/slack-ruby-bot/initializers/giphy_spec.rb +0 -18
@@ -1,38 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec/expectations'
|
4
|
+
|
2
5
|
RSpec::Matchers.define :respond_with_slack_messages do |expected|
|
3
6
|
include SlackRubyBot::SpecHelpers
|
7
|
+
|
4
8
|
match do |actual|
|
5
|
-
raise ArgumentError, 'respond_with_slack_messages expects an array of ordered responses'
|
6
|
-
client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new
|
7
|
-
def client.test_messages
|
8
|
-
@test_received_messages
|
9
|
-
end
|
9
|
+
raise ArgumentError, 'respond_with_slack_messages expects an array of ordered responses' if expected && !expected.respond_to?(:each)
|
10
10
|
|
11
|
-
|
12
|
-
super
|
13
|
-
@test_received_messages = @test_received_messages.nil? ? [] : @test_received_messages
|
14
|
-
@test_received_messages.push options
|
15
|
-
end
|
11
|
+
client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new
|
16
12
|
|
17
13
|
message_command = SlackRubyBot::Hooks::Message.new
|
18
14
|
channel, user, message, attachments = parse(actual)
|
19
15
|
|
20
|
-
|
16
|
+
@messages ||= []
|
17
|
+
allow(client).to receive(:message) do |options|
|
18
|
+
@messages.push options
|
19
|
+
end
|
21
20
|
|
22
|
-
allow(client).to receive(:message)
|
23
21
|
message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments))
|
24
|
-
|
22
|
+
|
25
23
|
@responses = []
|
26
|
-
|
27
|
-
|
24
|
+
|
25
|
+
if expected&.any?
|
26
|
+
expected.each do |exp|
|
27
|
+
@responses.push(expect(client).to(have_received(:message).with(hash_including(channel: channel, text: exp)).once))
|
28
|
+
end
|
29
|
+
else
|
30
|
+
expect(@messages.size).to be > 1
|
28
31
|
end
|
32
|
+
|
29
33
|
true
|
30
34
|
end
|
35
|
+
|
31
36
|
failure_message do |_actual|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
if expected&.any?
|
38
|
+
expected.map do |exp|
|
39
|
+
"Expected text: #{exp}, got #{@messages[expected.index(exp)] || 'none'}" unless @responses[expected.index(exp)]
|
40
|
+
end.compact.join("\n")
|
41
|
+
else
|
42
|
+
"Expected to receive multiple messages, got #{@messages.any? ? @messages.size : 'none'}"
|
35
43
|
end
|
36
|
-
message
|
37
44
|
end
|
38
45
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec/expectations'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :start_typing do |expected|
|
6
|
+
include SlackRubyBot::SpecHelpers
|
7
|
+
|
8
|
+
match do |actual|
|
9
|
+
client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new
|
10
|
+
|
11
|
+
message_command = SlackRubyBot::Hooks::Message.new
|
12
|
+
|
13
|
+
allow(client).to receive(:typing) do |options|
|
14
|
+
@test_options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
channel, user, message, attachments = parse(actual)
|
18
|
+
message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments))
|
19
|
+
|
20
|
+
matcher = have_received(:typing).once
|
21
|
+
matcher = matcher.with(expected) if expected&.any?
|
22
|
+
expect(client).to matcher
|
23
|
+
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
failure_message do |_actual|
|
28
|
+
message = "expected to receive typing with: #{expected} once,\n received:"
|
29
|
+
message += @test_options&.any? ? @test_options.inspect : ' none'
|
30
|
+
message
|
31
|
+
end
|
32
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackRubyBot
|
2
4
|
class Server
|
3
5
|
include Loggable
|
4
6
|
|
5
|
-
attr_accessor :token, :aliases
|
7
|
+
attr_accessor :token, :aliases
|
6
8
|
|
7
9
|
include SlackRubyBot::Hooks::HookSupport
|
8
10
|
|
@@ -11,7 +13,6 @@ module SlackRubyBot
|
|
11
13
|
def initialize(options = {})
|
12
14
|
@token = options[:token]
|
13
15
|
@aliases = options[:aliases]
|
14
|
-
@send_gifs = options[:send_gifs]
|
15
16
|
|
16
17
|
# Hook Handling
|
17
18
|
flush_hook_blocks
|
@@ -32,37 +33,17 @@ module SlackRubyBot
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def start!
|
35
|
-
@stopping = false
|
36
|
-
@async = false
|
37
36
|
client.start!
|
38
37
|
end
|
39
38
|
|
40
39
|
def start_async
|
41
|
-
@stopping = false
|
42
|
-
@async = true
|
43
40
|
client.start_async
|
44
41
|
end
|
45
42
|
|
46
43
|
def stop!
|
47
|
-
@stopping = true
|
48
44
|
client.stop! if @client
|
49
45
|
end
|
50
46
|
|
51
|
-
def restart!(wait = 1)
|
52
|
-
@async ? start_async : start!
|
53
|
-
rescue StandardError => e
|
54
|
-
case e.message
|
55
|
-
when 'account_inactive', 'invalid_auth'
|
56
|
-
logger.error "#{token}: #{e.message}, team will be deactivated."
|
57
|
-
@stopping = true
|
58
|
-
else
|
59
|
-
sleep wait
|
60
|
-
logger.error "#{e.message}, reconnecting in #{wait} second(s)."
|
61
|
-
logger.debug e
|
62
|
-
restart! [wait * 2, 60].min
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
47
|
private
|
67
48
|
|
68
49
|
def handle_exceptions
|
@@ -75,7 +56,7 @@ module SlackRubyBot
|
|
75
56
|
else
|
76
57
|
raise e
|
77
58
|
end
|
78
|
-
rescue Faraday::
|
59
|
+
rescue Faraday::TimeoutError, Faraday::ConnectionFailed, Faraday::SSLError => e
|
79
60
|
logger.error e
|
80
61
|
sleep 1 # ignore, try again
|
81
62
|
rescue StandardError => e
|
@@ -97,11 +78,7 @@ module SlackRubyBot
|
|
97
78
|
|
98
79
|
def client
|
99
80
|
@client ||= begin
|
100
|
-
client = SlackRubyBot::Client.new(aliases: aliases,
|
101
|
-
client.on :close do |_data|
|
102
|
-
@client = nil
|
103
|
-
restart! unless @stopping
|
104
|
-
end
|
81
|
+
client = SlackRubyBot::Client.new(aliases: aliases, token: token)
|
105
82
|
_hooks.client = client
|
106
83
|
|
107
84
|
client
|
data/lib/slack_ruby_bot.rb
CHANGED
Binary file
|
data/slack-ruby-bot.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
4
|
require 'slack-ruby-bot/version'
|
3
5
|
|
4
6
|
Gem::Specification.new do |s|
|
@@ -14,12 +16,13 @@ Gem::Specification.new do |s|
|
|
14
16
|
s.homepage = 'https://github.com/slack-ruby/slack-ruby-bot'
|
15
17
|
s.licenses = ['MIT']
|
16
18
|
s.summary = 'The easiest way to write a Slack bot in Ruby.'
|
19
|
+
s.required_ruby_version = '>= 2.3'
|
17
20
|
s.add_dependency 'hashie'
|
18
|
-
s.add_dependency 'slack-ruby-client', '>= 0.
|
21
|
+
s.add_dependency 'slack-ruby-client', '>= 0.14.0'
|
19
22
|
s.add_development_dependency 'rack-test'
|
20
23
|
s.add_development_dependency 'rake'
|
21
24
|
s.add_development_dependency 'rspec'
|
22
|
-
s.add_development_dependency 'rubocop', '0.
|
25
|
+
s.add_development_dependency 'rubocop', '0.80.1'
|
23
26
|
s.add_development_dependency 'vcr'
|
24
27
|
s.add_development_dependency 'webmock'
|
25
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe SlackRubyBot::App do
|
2
4
|
def app
|
3
5
|
SlackRubyBot::App.new
|
@@ -5,10 +7,71 @@ describe SlackRubyBot::App do
|
|
5
7
|
it_behaves_like 'a slack ruby bot'
|
6
8
|
|
7
9
|
describe '.instance' do
|
10
|
+
let(:token) { 'slack-api-token' }
|
11
|
+
let(:klass) { Class.new(SlackRubyBot::App) }
|
12
|
+
|
8
13
|
it 'creates an instance of the App subclass' do
|
9
|
-
klass = Class.new(SlackRubyBot::App)
|
10
14
|
expect(klass.instance.class).to be klass
|
11
15
|
end
|
16
|
+
|
17
|
+
it 'sets config.token from ENV' do
|
18
|
+
expect(klass.instance.config.token).to eq('test')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when token is not defined' do
|
22
|
+
before do
|
23
|
+
ENV.delete('SLACK_API_TOKEN')
|
24
|
+
SlackRubyBot::Config.token = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises error' do
|
28
|
+
expect { klass.instance }.to raise_error RuntimeError, 'Missing Slack API Token.'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when token is defined in ENV but not config' do
|
33
|
+
before do
|
34
|
+
SlackRubyBot::Config.token = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'sets config.token from ENV' do
|
38
|
+
expect(klass.instance.config.token).to eq('test')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when token is not defined in ENV but is defined in config' do
|
43
|
+
before do
|
44
|
+
ENV.delete('SLACK_API_TOKEN')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets config.token from config' do
|
48
|
+
expect(klass.instance.config.token).to eq('testtoken')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when aliases are defined in config only' do
|
53
|
+
let(:aliases) { %w[alias alias2] }
|
54
|
+
before do
|
55
|
+
SlackRubyBot::Config.aliases = aliases
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets config.aliases' do
|
59
|
+
expect(klass.instance.config.aliases).to eq(aliases)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when aliases are defined in ENV only' do
|
64
|
+
before do
|
65
|
+
ENV['SLACK_RUBY_BOT_ALIASES'] = 'alias3 alias4'
|
66
|
+
end
|
67
|
+
after do
|
68
|
+
ENV.delete('SLACK_RUBY_BOT_ALIASES')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets config.aliases from env' do
|
72
|
+
expect(klass.instance.config.aliases).to eq(%w[alias3 alias4])
|
73
|
+
end
|
74
|
+
end
|
12
75
|
end
|
13
76
|
|
14
77
|
describe 'executable' do
|
@@ -1,39 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe SlackRubyBot::Client do
|
2
|
-
describe '#
|
3
|
-
context '
|
4
|
-
|
5
|
-
|
4
|
+
describe '#allow_message_loops?' do
|
5
|
+
context 'with global allow_message_loops set to true' do
|
6
|
+
before do
|
7
|
+
SlackRubyBot::Config.allow_message_loops = true
|
6
8
|
end
|
7
|
-
|
8
|
-
|
9
|
-
subject.send_gifs = true
|
10
|
-
expect(subject.send_gifs?).to be false
|
9
|
+
it do
|
10
|
+
expect(subject.allow_message_loops?).to be true
|
11
11
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
context 'overridden locally' do
|
13
|
+
subject do
|
14
|
+
SlackRubyBot::Client.new(allow_message_loops: false)
|
15
|
+
end
|
16
|
+
it do
|
17
|
+
expect(subject.allow_message_loops?).to be false
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
expect(subject.send_gifs?).to be true
|
21
|
+
context 'with global allow_message_loops set to false' do
|
22
|
+
before do
|
23
|
+
SlackRubyBot::Config.allow_message_loops = false
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
-
SlackRubyBot::Config.send_gifs = false
|
26
|
-
expect(subject.send_gifs?).to be false
|
25
|
+
it do
|
26
|
+
expect(subject.allow_message_loops?).to be false
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
context 'overridden locally' do
|
29
|
+
subject do
|
30
|
+
SlackRubyBot::Client.new(allow_message_loops: true)
|
31
|
+
end
|
32
|
+
it do
|
33
|
+
expect(subject.allow_message_loops?).to be true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'overridden locally' do
|
38
|
+
subject do
|
39
|
+
SlackRubyBot::Client.new(allow_message_loops: true)
|
40
|
+
end
|
41
|
+
it do
|
42
|
+
expect(subject.allow_message_loops?).to be true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe '#allow_bot_messages?' do
|
47
|
+
context 'with global allow_bot_messages set to true' do
|
48
|
+
before do
|
49
|
+
SlackRubyBot::Config.allow_bot_messages = true
|
50
|
+
end
|
51
|
+
it do
|
52
|
+
expect(subject.allow_bot_messages?).to be true
|
53
|
+
end
|
54
|
+
context 'overridden locally' do
|
55
|
+
subject do
|
56
|
+
SlackRubyBot::Client.new(allow_bot_messages: false)
|
57
|
+
end
|
58
|
+
it do
|
59
|
+
expect(subject.allow_bot_messages?).to be false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context 'with global allow_bot_messages set to false' do
|
64
|
+
before do
|
65
|
+
SlackRubyBot::Config.allow_bot_messages = false
|
36
66
|
end
|
67
|
+
it do
|
68
|
+
expect(subject.allow_bot_messages?).to be false
|
69
|
+
end
|
70
|
+
context 'overridden locally' do
|
71
|
+
subject do
|
72
|
+
SlackRubyBot::Client.new(allow_bot_messages: true)
|
73
|
+
end
|
74
|
+
it do
|
75
|
+
expect(subject.allow_bot_messages?).to be true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context 'overridden locally' do
|
80
|
+
subject do
|
81
|
+
SlackRubyBot::Client.new(allow_bot_messages: true)
|
82
|
+
end
|
83
|
+
it do
|
84
|
+
expect(subject.allow_bot_messages?).to be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
describe '#message_to_self?' do
|
89
|
+
before do
|
90
|
+
allow(subject).to receive(:self).and_return(Hashie::Mash.new({ 'id' => 'U0K8CKKT1' }))
|
91
|
+
end
|
92
|
+
context 'with message to self' do
|
93
|
+
it do
|
94
|
+
expect(subject.message_to_self?(Hashie::Mash.new(user: 'U0K8CKKT1'))).to be true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context 'with message to another user' do
|
98
|
+
it do
|
99
|
+
expect(subject.message_to_self?(Hashie::Mash.new(user: 'U0K8CKKT2'))).to be false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
describe '#bot_message?' do
|
104
|
+
it 'bot message' do
|
105
|
+
expect(subject.bot_message?(Hashie::Mash.new(subtype: 'bot_message'))).to be true
|
106
|
+
end
|
107
|
+
it 'not bot message' do
|
108
|
+
expect(subject.bot_message?(Hashie::Mash.new(subtype: 'other'))).to be false
|
109
|
+
end
|
110
|
+
it 'no subtype' do
|
111
|
+
expect(subject.bot_message?(Hashie::Mash.new)).to be false
|
37
112
|
end
|
38
113
|
end
|
39
114
|
end
|