slack-ruby-bot 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.rubocop.yml +14 -1
  4. data/.rubocop_todo.yml +13 -36
  5. data/.travis.yml +7 -5
  6. data/CHANGELOG.md +9 -0
  7. data/DEPLOYMENT.md +61 -5
  8. data/Dangerfile +2 -0
  9. data/Gemfile +10 -3
  10. data/LICENSE.md +1 -1
  11. data/README.md +78 -10
  12. data/Rakefile +2 -0
  13. data/TUTORIAL.md +23 -0
  14. data/UPGRADING.md +8 -0
  15. data/examples/inventory/Gemfile +2 -0
  16. data/examples/inventory/inventorybot.rb +5 -1
  17. data/examples/market/Gemfile +4 -3
  18. data/examples/market/marketbot.rb +22 -15
  19. data/examples/minimal/Gemfile +2 -0
  20. data/examples/minimal/pongbot.rb +2 -0
  21. data/examples/weather/Gemfile +2 -0
  22. data/examples/weather/weatherbot.rb +2 -0
  23. data/lib/config/application.rb +4 -2
  24. data/lib/config/boot.rb +2 -0
  25. data/lib/config/environment.rb +3 -1
  26. data/lib/initializers/giphy.rb +2 -0
  27. data/lib/initializers/giphy_client.rb +2 -0
  28. data/lib/slack-ruby-bot.rb +3 -1
  29. data/lib/slack-ruby-bot/about.rb +3 -1
  30. data/lib/slack-ruby-bot/app.rb +2 -0
  31. data/lib/slack-ruby-bot/bot.rb +2 -0
  32. data/lib/slack-ruby-bot/client.rb +7 -4
  33. data/lib/slack-ruby-bot/commands.rb +2 -0
  34. data/lib/slack-ruby-bot/commands/about.rb +2 -0
  35. data/lib/slack-ruby-bot/commands/base.rb +12 -1
  36. data/lib/slack-ruby-bot/commands/help.rb +9 -7
  37. data/lib/slack-ruby-bot/commands/hi.rb +2 -0
  38. data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
  39. data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
  40. data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
  41. data/lib/slack-ruby-bot/commands/unknown.rb +2 -0
  42. data/lib/slack-ruby-bot/config.rb +3 -0
  43. data/lib/slack-ruby-bot/hooks.rb +2 -0
  44. data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
  45. data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -0
  46. data/lib/slack-ruby-bot/hooks/message.rb +5 -2
  47. data/lib/slack-ruby-bot/hooks/set.rb +3 -1
  48. data/lib/slack-ruby-bot/mvc.rb +2 -0
  49. data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
  50. data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
  51. data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
  52. data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
  53. data/lib/slack-ruby-bot/rspec.rb +3 -1
  54. data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
  55. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +2 -0
  56. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
  57. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -5
  58. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +16 -13
  59. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +27 -18
  60. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
  61. data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +2 -0
  62. data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
  63. data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
  64. data/lib/slack-ruby-bot/rspec/support/vcr.rb +2 -0
  65. data/lib/slack-ruby-bot/server.rb +2 -0
  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-app.png +0 -0
  70. data/slack-ruby-bot.gemspec +5 -2
  71. data/spec/slack-ruby-bot/app_spec.rb +2 -0
  72. data/spec/slack-ruby-bot/client_spec.rb +2 -0
  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_spec.rb +2 -0
  78. data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
  79. data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
  80. data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
  81. data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
  82. data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
  83. data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
  84. data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
  85. data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
  86. data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
  87. data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
  88. data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
  89. data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
  90. data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
  91. data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
  92. data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
  93. data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
  94. data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
  95. data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
  96. data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
  97. data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
  98. data/spec/slack-ruby-bot/commands/send_gif_spec.rb +2 -0
  99. data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
  100. data/spec/slack-ruby-bot/commands/send_message_with_gif_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 -0
  106. data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
  107. data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -0
  108. data/spec/slack-ruby-bot/hooks/message_spec.rb +3 -1
  109. data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
  110. data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +2 -0
  111. data/spec/slack-ruby-bot/initializers/giphy_spec.rb +2 -0
  112. data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
  113. data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
  114. data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
  115. data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
  116. data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
  117. data/spec/slack-ruby-bot/server_spec.rb +2 -0
  118. data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
  119. data/spec/slack-ruby-bot/version_spec.rb +2 -0
  120. data/spec/spec_helper.rb +2 -0
  121. metadata +12 -8
  122. data/screenshots/register-bot.png +0 -0
@@ -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::Client do
2
4
  describe '#send_gifs?' do
3
5
  context 'without giphy is false', unless: WithGiphy.env? do
@@ -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
@@ -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
@@ -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, if: WithGiphy.env? 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, if: WithGiphy.env? 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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Config do
2
4
  describe '.send_gifs?' do
3
5
  after { ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS' }
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Hooks::Message do
2
4
  let(:message_hook) { described_class.new }
3
5
 
@@ -5,7 +7,7 @@ describe SlackRubyBot::Hooks::Message do
5
7
  it 'doesn\'t raise an error when message is a frozen string' do
6
8
  message_hook.call(
7
9
  SlackRubyBot::Client.new,
8
- Hashie::Mash.new(text: 'message'.freeze)
10
+ Hashie::Mash.new(text: 'message')
9
11
  )
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::Hooks::Set do
2
4
  let(:client) { Slack::RealTime::Client.new }
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV.key?('WITH_GIPHY_CLIENT')
2
4
  describe Giphy do
3
5
  before do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV.key?('WITH_GIPHY')
2
4
  describe Giphy do
3
5
  let(:burrito_gif) { 'https://media3.giphy.com/media/xTiTndNDuNFxUW5Xoc/giphy.gif' }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe SlackRubyBot::MVC::Controller::Base, 'initialization' do
2
4
  let(:model) { double('model') }
3
5
  let(:view) { double('view') }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe RSpec do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe RSpec do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'no message' do |client, data, _match|
7
+ end
4
8
  command 'single message with as_user' do |client, data, _match|
5
9
  client.say(text: 'single response', channel: data.channel, as_user: true)
6
10
  end
@@ -25,6 +29,22 @@ describe RSpec do
25
29
  expect(message: "#{SlackRubyBot.config.user} single message")
26
30
  .to respond_with_slack_message(/single response/i)
27
31
  end
32
+ it 'respond with any message' do
33
+ expect(message: "#{SlackRubyBot.config.user} single message")
34
+ .to respond_with_slack_message
35
+ end
36
+ it 'correctly reports error' do
37
+ expect do
38
+ expect(message: "#{SlackRubyBot.config.user} single message")
39
+ .to respond_with_slack_message('another response')
40
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, "expected to receive message with text: another response once,\n received:[{:text=>\"single response\", :channel=>\"channel\"}]"
41
+ end
42
+ it 'correctly reports error without message' do
43
+ expect do
44
+ expect(message: "#{SlackRubyBot.config.user} no message")
45
+ .to respond_with_slack_message('another response')
46
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, "expected to receive message with text: another response once,\n received:none"
47
+ end
28
48
  it 'respond_with_single_message_using_partial_regex_match' do
29
49
  expect(message: "#{SlackRubyBot.config.user} single message")
30
50
  .to respond_with_slack_message(/si[n|N]gle/)
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe RSpec do
2
4
  let! :command do
3
5
  Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'do not respond' do |client, data, _match|
7
+ end
8
+ command 'respond once' do |client, data, _match|
9
+ client.say(text: 'response', channel: data.channel, as_user: true)
10
+ end
4
11
  command 'respond with as_user' do |client, data, _match|
5
12
  5.times do |i|
6
13
  client.say(text: "response #{i}", channel: data.channel, as_user: true)
@@ -29,6 +36,26 @@ describe RSpec do
29
36
  expect(message: "#{SlackRubyBot.config.user} respond 5 times")
30
37
  .to respond_with_slack_messages(expected_responses)
31
38
  end
39
+ it 'respond with multiple messages' do
40
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
41
+ .to respond_with_slack_messages
42
+ end
43
+ it 'respond once' do
44
+ expect do
45
+ expect(message: "#{SlackRubyBot.config.user} respond once")
46
+ .to respond_with_slack_messages
47
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, 'Expected to receive multiple messages, got 1'
48
+ end
49
+ it 'do not respond' do
50
+ expect(message: "#{SlackRubyBot.config.user} do not respond")
51
+ .to_not respond_with_slack_messages
52
+ end
53
+ it 'correctly reports error on do not respond' do
54
+ expect do
55
+ expect(message: "#{SlackRubyBot.config.user} do not respond")
56
+ .to respond_with_slack_messages
57
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, 'Expected to receive multiple messages, got none'
58
+ end
32
59
  it 'respond_with_multiple_messages_using_string_matches' do
33
60
  expected_responses = []
34
61
  5.times { |i| expected_responses.push("response #{i}") }
@@ -41,6 +68,15 @@ describe RSpec do
41
68
  expect(message: "#{SlackRubyBot.config.user} respond 5 times")
42
69
  .not_to respond_with_slack_messages(expected_responses)
43
70
  end
71
+ it 'correctly reports error' do
72
+ expect do
73
+ expected_responses = []
74
+ 6.times { |i| expected_responses.push("response #{i}") }
75
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
76
+ .to respond_with_slack_messages(expected_responses)
77
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError, 'Expected text: response 5, got none'
78
+ end
79
+
44
80
  it 'respond_with_multiple_messages_using_string_matches_with_extra_arg' do
45
81
  expected_responses = []
46
82
  5.times { |i| expected_responses.push("response #{i}") }