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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Default do
2
4
  it 'lowercase' do
3
5
  expect(message: SlackRubyBot.config.user).to respond_with_slack_message(SlackRubyBot::ABOUT)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot do
2
4
  def client
3
5
  SlackRubyBot::Client.new aliases: %w[:emoji: alias каспаров B0?.@(*^$]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  context 'optional fields to scan' do
3
5
  let! :command do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Unknown do
2
4
  def app
3
5
  SlackRubyBot::App.new
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe SlackRubyBot::App do
4
+ def app
5
+ SlackRubyBot::App.new
6
+ end
7
+
8
+ let(:client) { subject.send(:client) }
9
+ let(:message_hook) { SlackRubyBot::Hooks::Message.new }
10
+
11
+ context 'default' do
12
+ it 'does not respond to bot messages' do
13
+ expect(client).to_not receive(:message)
14
+ message_hook.call(client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", subtype: 'bot_message'))
15
+ end
16
+ end
17
+ context 'with allow_bot_messages=true' do
18
+ before do
19
+ SlackRubyBot::Config.allow_bot_messages = true
20
+ end
21
+ it 'responds to self' do
22
+ expect(client).to receive(:message)
23
+ message_hook.call(client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", subtype: 'bot_message'))
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Bot do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Bot) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Base do
2
4
  let! :command1 do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands, 'permitted?' do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot do
2
4
  def app
3
5
  SlackRubyBot::App.new
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,25 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Help do
2
4
  def app
3
5
  SlackRubyBot::App.new
4
6
  end
5
7
  it 'help' do
6
- message = <<MSG
7
- *Weather Bot* - This bot tells you the weather.
8
+ message = <<~MSG
9
+ *Weather Bot* - This bot tells you the weather.
8
10
 
9
- *Commands:*
10
- *clouds* - Tells you how many clouds there're above you.
11
- *command_without_description*
12
- *What's the weather in <city>?* - Tells you the weather in a <city>.
11
+ *Commands:*
12
+ *clouds* - Tells you how many clouds there're above you.
13
+ *command_without_description*
14
+ *What's the weather in <city>?* - Tells you the weather in a <city>.
13
15
 
14
- *Other commands:*
15
- *help* - Shows help information.
16
- *hi* - Says hello.
17
- *hello* - Says hello.
16
+ *Other commands:*
17
+ *help* - Shows help information.
18
+ *hi* - Says hello.
19
+ *hello* - Says hello.
18
20
 
19
- For getting description of the command use: *help <command>*
21
+ For getting description of the command use: *help <command>*
20
22
 
21
- For more information see https://github.com/slack-ruby/slack-ruby-bot, please.
22
- MSG
23
+ For more information see https://github.com/slack-ruby/slack-ruby-bot, please.
24
+ MSG
23
25
 
24
26
  expect(message: "#{SlackRubyBot.config.user} help").to respond_with_slack_message(message)
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Hi do
2
4
  def app
3
5
  SlackRubyBot::App.new
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe SlackRubyBot::Commands do
4
+ let! :command do
5
+ Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'non_breaking_space' do |client, data, match|
7
+ client.say(channel: data.channel, text: match['expression'])
8
+ end
9
+ end
10
+ end
11
+ it 'sends a message with non-breaking space after bot name' do
12
+ expect(message: "#{SlackRubyBot.config.user}\u00a0non_breaking_space message").to respond_with_slack_message('message')
13
+ end
14
+ it 'sends a message with non-breaking space after command' do
15
+ expect(message: "#{SlackRubyBot.config.user} non_breaking_space\u00a0message").to respond_with_slack_message('message')
16
+ end
17
+ it 'sends a message with all non-breaking spaces' do
18
+ expect(message: "#{SlackRubyBot.config.user}\u00a0non_breaking_space\u00a0message").to respond_with_slack_message('message')
19
+ end
20
+ it 'sends a message with trailing non-breaking spaces' do
21
+ expect(message: "#{SlackRubyBot.config.user} non_breaking_space message\u00a0").to respond_with_slack_message("message\u00a0")
22
+ end
23
+ it 'sends a message with multiple non-breaking spaces' do
24
+ expect(message: "#{SlackRubyBot.config.user} non_breaking_space message1\u00a0message2").to respond_with_slack_message("message1\u00a0message2")
25
+ end
26
+ it 'sends a message with non-breaking spaces on multiple lines' do
27
+ expect(message: "#{SlackRubyBot.config.user} non_breaking_space message1\u00a0message2\nmessage3\u00a0message4").to respond_with_slack_message("message1\u00a0message2\nmessage3\u00a0message4")
28
+ end
29
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Base do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Support::Attrs do
2
4
  let(:help_attrs) { described_class.new('WeatherBot') }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Support::Help do
2
4
  let(:bot_class) { Testing::WeatherBot }
3
5
  let(:command_class) { Testing::HelloCommand }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Support::Match do
2
4
  context 'initialized with invalid args' do
3
5
  subject { -> { described_class.new('invalid-match-data') } }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Commands::Unknown do
2
4
  it 'invalid command' do
3
5
  expect(message: "#{SlackRubyBot.config.user} foobar").to respond_with_slack_message("Sorry <@user>, I don't understand that command!")
@@ -1,61 +1,6 @@
1
- describe SlackRubyBot::Config do
2
- describe '.send_gifs?' do
3
- after { ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS' }
4
-
5
- context 'without giphy is false', unless: WithGiphy.env? do
6
- it 'by default' do
7
- expect(SlackRubyBot::Config.send_gifs?).to be false
8
- end
9
- it 'when set to true' do
10
- SlackRubyBot::Config.send_gifs = true
11
- expect(SlackRubyBot::Config.send_gifs?).to be false
12
- end
13
- it 'when set to true via SLACK_RUBY_BOT_SEND_GIFS' do
14
- ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
15
- expect(SlackRubyBot::Config.send_gifs?).to be false
16
- end
17
- end
18
- context 'with giphy', if: WithGiphy.env? do
19
- it 'default is true' do
20
- expect(SlackRubyBot::Config.send_gifs?).to be true
21
- end
22
- context 'set to false' do
23
- it 'is false' do
24
- SlackRubyBot::Config.send_gifs = false
25
- expect(SlackRubyBot::Config.send_gifs?).to be false
26
- end
27
- end
28
- context 'set to false via SLACK_RUBY_BOT_SEND_GIFS' do
29
- it 'is false' do
30
- ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
31
- expect(SlackRubyBot::Config.send_gifs?).to be false
32
- end
33
- end
34
- context 'set to true' do
35
- it 'is true' do
36
- SlackRubyBot::Config.send_gifs = true
37
- expect(SlackRubyBot::Config.send_gifs?).to be true
38
- end
39
- end
40
- context 'set to true via SLACK_RUBY_BOT_SEND_GIFS' do
41
- it 'is true' do
42
- ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
43
- expect(SlackRubyBot::Config.send_gifs?).to be true
44
- end
45
- end
46
- context 'when using both methods' do
47
- it 'config setting takes precedence' do
48
- ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
49
- SlackRubyBot::Config.send_gifs = false
50
- expect(SlackRubyBot::Config.send_gifs?).to be false
51
- ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
52
- SlackRubyBot::Config.send_gifs = true
53
- expect(SlackRubyBot::Config.send_gifs?).to be true
54
- end
55
- end
56
- end
57
- end
1
+ # frozen_string_literal: true
58
2
 
3
+ describe SlackRubyBot::Config do
59
4
  describe '#reset!' do
60
5
  it 'sets all config attributes to nil' do
61
6
  SlackRubyBot::Config::ATTRS.each do |attr|
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe SlackRubyBot::Hooks::Hello do
4
+ let(:logger) { double(:logger, info: nil) }
5
+ let(:hello_hook) { described_class.new(logger) }
6
+
7
+ describe '#call' do
8
+ let(:team_name) { 'Example Team' }
9
+ let(:team_id) { SecureRandom.uuid }
10
+ let(:team_domain) { 'example' }
11
+ let(:team) { double(:team, name: team_name, id: team_id, domain: team_domain) }
12
+ let(:client) { instance_double(SlackRubyBot::Client, team: team) }
13
+
14
+ def receive_hello
15
+ hello_hook.call(client, double)
16
+ end
17
+
18
+ it 'logs the connection' do
19
+ expect(logger).to receive(:info).with("Successfully connected team #{team_name} (#{team_id}) to https://#{team_domain}.slack.com.")
20
+ receive_hello
21
+ end
22
+
23
+ context 'with no client' do
24
+ let(:client) { nil }
25
+ it 'does nothing' do
26
+ expect(logger).not_to receive(:info)
27
+ receive_hello
28
+ end
29
+ end
30
+
31
+ context 'when client has no team' do
32
+ let(:team) { nil }
33
+ it 'does nothing' do
34
+ expect(logger).not_to receive(:info)
35
+ receive_hello
36
+ end
37
+ end
38
+
39
+ context 'when hook is received multiple times' do
40
+ before do
41
+ receive_hello
42
+ end
43
+
44
+ it 'logs the reconnections' do
45
+ expect(logger).to receive(:info).with(/^Successfully reconnected .+ after \S+s\.$/).twice
46
+ receive_hello
47
+ receive_hello
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Hooks::HookSupport do
2
4
  subject do
3
5
  Class.new do
@@ -54,11 +56,6 @@ describe SlackRubyBot::Hooks::HookSupport do
54
56
  end
55
57
  end
56
58
 
57
- describe '#hooks' do
58
- subject { super().new }
59
- it { expect(subject.hooks).to eq subject.send(:_hooks) }
60
- end
61
-
62
59
  describe '#_hooks' do
63
60
  it 'returns a SlackRubyBot::Hooks::Set instance' do
64
61
  hooks_set = subject.new.send(:_hooks)
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Hooks::Message do
2
4
  let(:message_hook) { described_class.new }
3
5
 
4
6
  describe '#call' do
5
7
  it 'doesn\'t raise an error when message is a frozen string' do
6
- message_hook.call(
7
- SlackRubyBot::Client.new,
8
- Hashie::Mash.new(text: 'message'.freeze)
9
- )
8
+ expect do
9
+ message_hook.call(
10
+ SlackRubyBot::Client.new,
11
+ Hashie::Mash.new(text: 'message'.freeze) # rubocop:disable Style/RedundantFreeze
12
+ )
13
+ end.to_not raise_error
10
14
  end
11
15
  end
12
16
 
@@ -30,37 +34,6 @@ describe SlackRubyBot::Hooks::Message do
30
34
  expect(built_in_command_classes).to_not include SlackRubyBot::Commands::Unknown
31
35
  end
32
36
  end
33
- describe '#message_to_self_not_allowed?' do
34
- context 'with allow_message_loops set to true' do
35
- before do
36
- SlackRubyBot::Config.allow_message_loops = true
37
- end
38
- it do
39
- expect(message_hook.send(:message_to_self_not_allowed?)).to be false
40
- end
41
- end
42
- context 'with allow_message_loops set to false' do
43
- before do
44
- SlackRubyBot::Config.allow_message_loops = false
45
- end
46
- it do
47
- expect(message_hook.send(:message_to_self_not_allowed?)).to be true
48
- end
49
- end
50
- end
51
- describe '#message_to_self?' do
52
- let(:client) { Hashie::Mash.new(self: { 'id' => 'U0K8CKKT1' }) }
53
- context 'with message to self' do
54
- it do
55
- expect(message_hook.send(:message_to_self?, client, Hashie::Mash.new(user: 'U0K8CKKT1'))).to be true
56
- end
57
- end
58
- context 'with message to another user' do
59
- it do
60
- expect(message_hook.send(:message_to_self?, client, Hashie::Mash.new(user: 'U0K8CKKT2'))).to be false
61
- end
62
- end
63
- end
64
37
  describe '#message' do
65
38
  let(:client) { Hashie::Mash.new(self: { 'id' => 'U0K8CKKT1' }) }
66
39
  it 'invokes a command' do