slack-ruby-bot 0.11.2 → 0.16.0

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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.gitignore +3 -2
  4. data/.rubocop.yml +14 -1
  5. data/.rubocop_todo.yml +14 -42
  6. data/.travis.yml +11 -13
  7. data/CHANGELOG.md +39 -6
  8. data/CONTRIBUTING.md +5 -1
  9. data/DEPLOYMENT.md +63 -9
  10. data/Dangerfile +4 -0
  11. data/Gemfile +11 -7
  12. data/LICENSE.md +1 -1
  13. data/MIGRATION.md +13 -0
  14. data/README.md +133 -65
  15. data/Rakefile +2 -0
  16. data/TUTORIAL.md +23 -0
  17. data/UPGRADING.md +50 -0
  18. data/examples/inventory/Gemfile +2 -0
  19. data/examples/inventory/inventorybot.rb +5 -1
  20. data/examples/market/Gemfile +4 -3
  21. data/examples/market/marketbot.rb +22 -15
  22. data/examples/minimal/Gemfile +3 -1
  23. data/examples/minimal/pongbot.rb +2 -0
  24. data/examples/weather/Gemfile +2 -0
  25. data/examples/weather/weatherbot.rb +2 -0
  26. data/lib/config/application.rb +4 -2
  27. data/lib/config/boot.rb +2 -0
  28. data/lib/config/environment.rb +3 -1
  29. data/lib/slack-ruby-bot.rb +3 -1
  30. data/lib/slack-ruby-bot/about.rb +3 -1
  31. data/lib/slack-ruby-bot/app.rb +18 -12
  32. data/lib/slack-ruby-bot/bot.rb +3 -1
  33. data/lib/slack-ruby-bot/client.rb +25 -23
  34. data/lib/slack-ruby-bot/commands.rb +2 -0
  35. data/lib/slack-ruby-bot/commands/about.rb +3 -1
  36. data/lib/slack-ruby-bot/commands/base.rb +13 -21
  37. data/lib/slack-ruby-bot/commands/help.rb +10 -8
  38. data/lib/slack-ruby-bot/commands/hi.rb +3 -1
  39. data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
  40. data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
  41. data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
  42. data/lib/slack-ruby-bot/commands/unknown.rb +3 -1
  43. data/lib/slack-ruby-bot/config.rb +7 -7
  44. data/lib/slack-ruby-bot/hooks.rb +2 -0
  45. data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
  46. data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -6
  47. data/lib/slack-ruby-bot/hooks/message.rb +11 -10
  48. data/lib/slack-ruby-bot/hooks/set.rb +3 -1
  49. data/lib/slack-ruby-bot/mvc.rb +2 -0
  50. data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
  51. data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
  52. data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
  53. data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
  54. data/lib/slack-ruby-bot/rspec.rb +3 -1
  55. data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
  56. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +4 -1
  57. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
  58. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -7
  59. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +15 -14
  60. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +26 -19
  61. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
  62. data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +3 -1
  63. data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
  64. data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
  65. data/lib/slack-ruby-bot/server.rb +5 -28
  66. data/lib/slack-ruby-bot/support/loggable.rb +2 -0
  67. data/lib/slack-ruby-bot/version.rb +3 -1
  68. data/lib/slack_ruby_bot.rb +2 -0
  69. data/screenshots/create-classic-app.png +0 -0
  70. data/slack-ruby-bot.gemspec +6 -3
  71. data/spec/slack-ruby-bot/app_spec.rb +64 -1
  72. data/spec/slack-ruby-bot/client_spec.rb +103 -28
  73. data/spec/slack-ruby-bot/commands/about_spec.rb +2 -0
  74. data/spec/slack-ruby-bot/commands/aliases_spec.rb +2 -0
  75. data/spec/slack-ruby-bot/commands/attachment_spec.rb +2 -0
  76. data/spec/slack-ruby-bot/commands/bot_message_spec.rb +2 -0
  77. data/spec/slack-ruby-bot/commands/bot_messages_spec.rb +26 -0
  78. data/spec/slack-ruby-bot/commands/bot_spec.rb +2 -0
  79. data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
  80. data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
  81. data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
  82. data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
  83. data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
  84. data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
  85. data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
  86. data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
  87. data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
  88. data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
  89. data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
  90. data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
  91. data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
  92. data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
  93. data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
  94. data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
  95. data/spec/slack-ruby-bot/commands/non_breaking_space_spec.rb +29 -0
  96. data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
  97. data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
  98. data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
  99. data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
  100. data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
  101. data/spec/slack-ruby-bot/commands/support/attrs_spec.rb +2 -0
  102. data/spec/slack-ruby-bot/commands/support/help_spec.rb +2 -0
  103. data/spec/slack-ruby-bot/commands/support/match_spec.rb +2 -0
  104. data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -0
  105. data/spec/slack-ruby-bot/config_spec.rb +2 -57
  106. data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
  107. data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -5
  108. data/spec/slack-ruby-bot/hooks/message_spec.rb +8 -35
  109. data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
  110. data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
  111. data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
  112. data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
  113. data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
  114. data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
  115. data/spec/slack-ruby-bot/server_spec.rb +6 -33
  116. data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
  117. data/spec/slack-ruby-bot/version_spec.rb +2 -0
  118. data/spec/spec_helper.rb +3 -6
  119. data/{lib/slack-ruby-bot/rspec → spec}/support/fixtures/slack/migration_in_progress.yml +0 -0
  120. data/{lib/slack-ruby-bot/rspec → spec}/support/vcr.rb +2 -0
  121. metadata +28 -29
  122. data/lib/initializers/giphy.rb +0 -8
  123. data/lib/initializers/giphy_client.rb +0 -39
  124. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_burrito.yml +0 -69
  125. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito.yml +0 -71
  126. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito_rated_y.yml +0 -71
  127. data/screenshots/register-bot.png +0 -0
  128. data/spec/slack-ruby-bot/commands/send_gif_spec.rb +0 -25
  129. data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +0 -38
  130. data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +0 -28
  131. 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' unless expected.respond_to? :each
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
- def client.say(options = {})
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
- allow(Giphy).to receive(:random) if defined?(Giphy)
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
- @messages = client.test_messages
22
+
25
23
  @responses = []
26
- expected.each do |exp|
27
- @responses.push(expect(client).to(have_received(:message).with(hash_including(channel: channel, text: exp)).once))
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
- message = ''
33
- expected.each do |exp|
34
- message += "Expected text: #{exp}, got #{@messages[expected.index(exp)] || 'No Response'}\n" unless @responses[expected.index(exp)]
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,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.configure do |config|
2
- config.before :all do
4
+ config.before :each do
3
5
  ENV['SLACK_API_TOKEN'] ||= 'test'
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.configure do |config|
2
4
  config.before :each do
3
5
  SlackRubyBot.configure do |c|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackRubyBot
2
4
  module SpecHelpers
3
5
  private
@@ -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, :send_gifs
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::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e
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, send_gifs: send_gifs, token: token)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackRubyBot
2
4
  module Loggable
3
5
  def self.included(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackRubyBot
2
- VERSION = '0.11.2'.freeze
4
+ VERSION = '0.16.0'
3
5
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'slack-ruby-bot'
@@ -1,4 +1,6 @@
1
- $LOAD_PATH.push File.expand_path('../lib', __FILE__)
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.6.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.58.2'
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 '#send_gifs?' do
3
- context 'without giphy is false', unless: WithGiphy.env? do
4
- it 'by default' do
5
- expect(subject.send_gifs?).to be false
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
- it 'when set to true' do
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
- it 'when set to true via config' do
14
- SlackRubyBot::Config.send_gifs = true
15
- expect(SlackRubyBot::Config.send_gifs?).to be false
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
- context 'with giphy', if: WithGiphy.env? do
20
- it 'default is true' do
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
- it 'defaults to SlackRubyBot::Config.send_gifs? if set' do
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
- it 'client setting takes precedence' do
30
- SlackRubyBot::Config.send_gifs = true
31
- subject.send_gifs = false
32
- expect(subject.send_gifs?).to be false
33
- SlackRubyBot::Config.send_gifs = false
34
- subject.send_gifs = true
35
- expect(subject.send_gifs?).to be true
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