slack-ruby-bot 0.12.0 → 0.13.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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22dc3beb892b34e2ac402dda4e3406b06ad7b60d25c6db1098517934f599a000
4
- data.tar.gz: 8d089bd14bf6a096a89711627f459504bc3ba6a1dc04d1c45eff4c40476cf8ab
3
+ metadata.gz: f7cdc662d2370824e2b531aecde4c20b1f55e895e8e10d9c1804ca44a160b884
4
+ data.tar.gz: 3b5e9e13786df070f3d400c96e4752b4a6e2608472ab889d30e20e3ba95df6d1
5
5
  SHA512:
6
- metadata.gz: ff99ab182faab024601afe41a40fa8b66c589aeaf66d02819ad05196200e4ef3d6cd7e5fae6c670630f3b7225d96fc33d0031e370852b3ba6bdd33acfc182a22
7
- data.tar.gz: dd313bbae823189799d92888222f9433a6cba629aba7ac7e922dfd7154317c3332ad1ff1246a6537ec2000626826866bb4ebcf2fb857aac614609cedcd6ba0b2
6
+ metadata.gz: 1018f35fb9be750feaf55a420b7ed6faa305e3e3ff6ea6e271db16951e898893b1a96ad184103e37a47e24f28adef7cecee02788821c37ac34e0f7f916620d5a
7
+ data.tar.gz: a838815a6d65920fe1e1602e606e3bb73ab55c0176c9f565166f87d8cc643b42e37ab785f672ea651d2a156e93de68bf0eeff16b5237da0e6a75b7a98d7c2490
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
+ .bundle
2
+ .DS_Store
1
3
  .env
2
- pkg
3
4
  Gemfile.lock
4
- .bundle
5
+ pkg
@@ -1,4 +1,5 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.3
2
3
  Exclude:
3
4
  - vendor/**/*
4
5
  - examples/**/vendor/**/*
@@ -7,10 +8,22 @@ AllCops:
7
8
  Metrics:
8
9
  Enabled: false
9
10
 
10
- Metrics/LineLength:
11
+ Layout/LineLength:
11
12
  Max: 512
12
13
 
13
14
  Style/Documentation:
14
15
  Enabled: false
15
16
 
17
+ Style/HashEachMethods:
18
+ Enabled: true
19
+
20
+ Style/HashTransformKeys:
21
+ Enabled: true
22
+
23
+ Style/HashTransformValues:
24
+ Enabled: true
25
+
26
+ Style/ModuleFunction:
27
+ Enabled: false
28
+
16
29
  inherit_from: .rubocop_todo.yml
@@ -1,36 +1,29 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-08-27 14:16:34 +0200 using RuboCop version 0.58.2.
3
+ # on 2020-03-28 18:37:09 -0400 using RuboCop version 0.80.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 2
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: EnforcedStyle.
12
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
- Layout/IndentHeredoc:
14
- Exclude:
15
- - 'lib/slack-ruby-bot/commands/help.rb'
16
- - 'spec/slack-ruby-bot/commands/help_spec.rb'
17
-
18
9
  # Offense count: 1
19
10
  Lint/DuplicateMethods:
20
11
  Exclude:
21
12
  - 'lib/slack-ruby-bot/hooks/set.rb'
22
13
 
23
14
  # Offense count: 2
24
- Lint/HandleExceptions:
15
+ # Configuration parameters: AllowComments.
16
+ Lint/SuppressedException:
25
17
  Exclude:
26
18
  - 'lib/initializers/giphy.rb'
27
19
  - 'lib/initializers/giphy_client.rb'
28
20
 
29
21
  # Offense count: 1
30
- # Cop supports --auto-correct.
31
- Lint/UnneededCopEnableDirective:
22
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
23
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
24
+ Naming/FileName:
32
25
  Exclude:
33
- - 'Gemfile'
26
+ - 'lib/slack-ruby-bot.rb'
34
27
 
35
28
  # Offense count: 2
36
29
  # Configuration parameters: EnforcedStyle.
@@ -51,27 +44,11 @@ Style/DoubleNegation:
51
44
  Exclude:
52
45
  - 'lib/slack-ruby-bot/commands/base.rb'
53
46
 
54
- # Offense count: 5
55
- # Cop supports --auto-correct.
56
- Style/ExpandPathArguments:
57
- Exclude:
58
- - 'lib/config/application.rb'
59
- - 'lib/config/environment.rb'
60
- - 'lib/slack-ruby-bot.rb'
61
- - 'slack-ruby-bot.gemspec'
62
-
63
- # Offense count: 2
64
- # Cop supports --auto-correct.
65
- Style/IfUnlessModifier:
66
- Exclude:
67
- - 'lib/slack-ruby-bot/commands/support/match.rb'
68
- - 'lib/slack-ruby-bot/mvc/controller/base.rb'
69
-
70
- # Offense count: 2
47
+ # Offense count: 1
71
48
  # Cop supports --auto-correct.
72
- # Configuration parameters: EnforcedStyle.
73
- # SupportedStyles: module_function, extend_self
74
- Style/ModuleFunction:
49
+ # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
50
+ # SupportedStyles: predicate, comparison
51
+ Style/NumericPredicate:
75
52
  Exclude:
76
- - 'lib/initializers/giphy_client.rb'
77
- - 'lib/slack-ruby-bot/config.rb'
53
+ - 'spec/**/*'
54
+ - 'examples/market/marketbot.rb'
@@ -4,7 +4,7 @@ cache: bundler
4
4
 
5
5
  matrix:
6
6
  include:
7
- - rvm: 2.3.0
7
+ - rvm: 2.6.5
8
8
  script:
9
9
  - bundle exec danger
10
10
  - rvm: 2.3.0
@@ -12,14 +12,16 @@ matrix:
12
12
  - rvm: 2.3.0
13
13
  env: CONCURRENCY=faye-websocket
14
14
  - rvm: 2.3.0
15
+ env: CONCURRENCY=async-websocket
16
+ - rvm: 2.6.5
15
17
  env: CONCURRENCY=celluloid-io WITH_GIPHY=true
16
- - rvm: 2.3.0
18
+ - rvm: 2.6.5
17
19
  env: CONCURRENCY=faye-websocket WITH_GIPHY=true
18
- - rvm: 2.3.0
20
+ - rvm: 2.6.5
19
21
  env: CONCURRENCY=celluloid-io WITH_GIPHY_CLIENT=true
20
- - rvm: 2.3.0
22
+ - rvm: 2.6.5
21
23
  env: CONCURRENCY=faye-websocket WITH_GIPHY_CLIENT=true
22
- - rvm: 2.5
24
+ - rvm: 2.6.5
23
25
  env: CONCURRENCY=async-websocket WITH_GIPHY_CLIENT=true
24
26
  - rvm: ruby-head
25
27
  - rvm: jruby-head
@@ -1,3 +1,12 @@
1
+ ### 0.13.0 (2020/3/28)
2
+
3
+ * [#244](https://github.com/slack-ruby/slack-ruby-bot/pull/244): Change log message when the bot is reconnected - [@wasabigeek](https://github.com/wasabigeek).
4
+ * [#209](https://github.com/slack-ruby/slack-ruby-bot/pull/209): Allow `respond_to_slack_message` and `respond_to_slack_messages` without arguments - [@dblock](https://github.com/dblock).
5
+ * [#216](https://github.com/slack-ruby/slack-ruby-bot/pull/216): Added `start_typing` RSpec matcher - [@dblock](https://github.com/dblock).
6
+ * [#214](https://github.com/slack-ruby/slack-ruby-bot/pull/214): Add passenger deployment documentation - [@cybercrediators](https://github.com/cybercrediators).
7
+ * [#220](https://github.com/slack-ruby/slack-ruby-bot/pull/220): Updated examples/market to pull from IEX instead of defunct yahoo service - [@corprew](https://github.com/corprew).
8
+ * [#246](https://github.com/slack-ruby/slack-ruby-bot/pull/246): Drop support for Ruby 2.2 - [@dblock](https://github.com/dblock).
9
+
1
10
  ### 0.12.0 (2019/2/25)
2
11
 
3
12
  * [#203](https://github.com/slack-ruby/slack-ruby-bot/pull/203): Removing restart logic - [@RodneyU215](https://github.com/RodneyU215).
@@ -1,16 +1,20 @@
1
1
  ## Installation
2
2
 
3
- Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot).
3
+ To integrate your bot with Slack, you must first create a new [Slack App](https://api.slack.com/apps).
4
4
 
5
- ![](screenshots/register-bot.png)
6
-
7
- On the next screen, note the API token.
5
+ ![](screenshots/create-app.png)
8
6
 
9
7
  ### Environment
10
8
 
9
+ #### OAuth Code Grant
10
+
11
+ Once created, go to the app's Basic Info tab and grab the Client ID and Client Secret. You'll need these in order complete an [OAuth code grant flow](https://api.slack.com/docs/oauth#flow) as described at [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server). A successful flow will result in the receipt of an API token for the specific team that is granting access.
12
+
13
+ Alternatively, you can still [generate a legacy API token](https://api.slack.com/custom-integrations/legacy-tokens) for your app and use it for some interactions.
14
+
11
15
  #### SLACK_API_TOKEN
12
16
 
13
- Set SLACK_API_TOKEN from the Bot integration settings on Slack.
17
+ Set the SLACK_API_TOKEN environment variable using the token received above.
14
18
 
15
19
  ```
16
20
  heroku config:add SLACK_API_TOKEN=...
@@ -31,3 +35,55 @@ heroku config:add SLACK_RUBY_BOT_ALIASES=":pong: table-tennis ping-pong"
31
35
  ### Heroku Idling
32
36
 
33
37
  Heroku free tier applications will idle. Either pay 7$ a month for the hobby dyno or use [UptimeRobot](http://uptimerobot.com) or similar to prevent your instance from sleeping or pay for a production dyno.
38
+
39
+ ### Passenger Deployment
40
+
41
+ Deploying on your self-hosted server is fairly easy, it's pretty much following the [tutorial](https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby), but there are some configuration details to pay attention to.
42
+
43
+ + Change or add the `gem 'puma'` entry in your `Gemfile` to `gem 'passenger'` and `bundle` it
44
+ + OPTIONAL: To use passenger for developing too, change the `Procfile` to `web: bundle exec passenger start`, to configure the local passenger you could provide an optional `Passenger.json` file ([configuration options](https://www.phusionpassenger.com/library/config/standalone/reference/))
45
+ + If you want to keep your logs etc. in the correct folders, you could add empty `public/`, `tmp/` and `log` directories. Passenger e.g. will automatically use them for local log files.
46
+ + Make sure, the right ruby version is [installed](https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/install_language_runtime.html) and your passenger is [ready](https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/install_passenger_main.html) to go.
47
+ + Clone the repository on your server (You could create a separate user for this) and install the dependencies, by running `bundle install` ([More information](https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/xenial/deploy_app.html))
48
+ + Edit the web-server configuration according to the examples below
49
+ + `PassengerMaxPreloaderIdleTime 0` or `passenger_max_preloader_idle_time 0;` makes sure to not automatically shut down the process after 5 minutes
50
+ + `PassengerPreStart http://url:port` or `passenger_pre_start http://url:port` will startup the application instantly, without the first HTTP GET-request needed for passenger
51
+ + To get the `/path/to/ruby` run `passenger-config about ruby-command` and copy the displayed path
52
+ + Check the config (`nginx -t`) and restart the server with `service nginx restart`
53
+ + Execute `passenger-status --verbose` to check if your app is working correctly
54
+ + Optional: restart the passenger app via `passenger-config restart-app /var/www/bot`
55
+
56
+ #### Nginx
57
+
58
+ ```
59
+ server {
60
+ listen 80;
61
+ server_name example.com;
62
+ root /var/www/bot/public;
63
+ passenger_enabled on;
64
+ passenger_ruby /path/to/ruby
65
+ passenger_max_preloader_idle_time 0;
66
+ passenger_app_type rack;
67
+ }
68
+
69
+ passenger_pre_start http://example.com:80/;
70
+ ```
71
+
72
+ #### Apache
73
+
74
+ ```
75
+ <VirtualHost *:80>
76
+ ServerName example.com
77
+ DocumentRoot /var/www/bot/public
78
+ PassengerRuby /path/to/ruby
79
+ PassengerMaxPreloaderIdleTime 0
80
+
81
+ <Directory /var/www/bot/public>
82
+ Allow from all
83
+ Options -MultiViews
84
+ Require all granted
85
+ </Directory>
86
+ </VirtualHost>
87
+
88
+ PassengerPreStart http://example.com:80/
89
+ ```
data/Dangerfile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  danger.import_dangerfile(gem: 'slack-ruby-danger')
data/Gemfile CHANGED
@@ -1,10 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem ENV['CONCURRENCY'], require: false if ENV.key?('CONCURRENCY')
6
-
7
- # rubocop:enable Bundler/OrderedGems
7
+ if ENV.key?('CONCURRENCY')
8
+ case ENV['CONCURRENCY']
9
+ when 'async-websocket'
10
+ gem 'async-websocket', '~> 0.8.0', require: false
11
+ else
12
+ gem ENV['CONCURRENCY'], require: false
13
+ end
14
+ end
8
15
 
9
16
  gem 'giphy', require: false if ENV.key?('WITH_GIPHY')
10
17
  gem 'GiphyClient', require: false if ENV.key?('WITH_GIPHY_CLIENT')
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2015-2016 Daniel Doubrovkine, Artsy and Contributors
3
+ Copyright (c) 2015-2020 Daniel Doubrovkine, Artsy and Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -19,8 +19,7 @@ If you are not familiar with Slack bots or Slack API concepts, you might want to
19
19
 
20
20
  ## Stable Release
21
21
 
22
- You're reading the documentation for the **stable** release of slack-ruby-bot, v0.12.0.
23
- See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
22
+ You're reading the documentation for the **stable** release of slack-ruby-bot, v0.13.0. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
24
23
 
25
24
  ## Usage
26
25
 
@@ -32,7 +31,7 @@ See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING
32
31
  source 'https://rubygems.org'
33
32
 
34
33
  gem 'slack-ruby-bot'
35
- gem 'async-websocket'
34
+ gem 'async-websocket', '~>0.8.0'
36
35
  ```
37
36
 
38
37
  #### pongbot.rb
@@ -269,7 +268,7 @@ class Market < SlackRubyBot::Bot
269
268
  command 'help' do |client, data, match|
270
269
  user_command = match[:expression]
271
270
  help_attrs = SlackRubyBot::Commands::Support::Help.instance.find_command_help_attrs(user_command)
272
- client.say(channel: data.channel, text: "#{help_attrs.command_desc}\n\n#{help_attrs.command_long_desc}"
271
+ client.say(channel: data.channel, text: "#{help_attrs.command_desc}\n\n#{help_attrs.command_long_desc}")
273
272
  end
274
273
  end
275
274
  ```
@@ -381,7 +380,7 @@ Get help.
381
380
 
382
381
  Hooks are event handlers and respond to Slack RTM API [events](https://api.slack.com/events), such as [hello](lib/slack-ruby-bot/hooks/hello.rb) or [message](lib/slack-ruby-bot/hooks/message.rb). You can implement your own in a couple of ways:
383
382
 
384
- #### Implement and register a Hook Handler
383
+ #### Implementing and registering a Hook Handler
385
384
 
386
385
  A Hook Handler is any object that respond to a `call` message, like a proc, instance of an object, class with a `call` class method, etc.
387
386
 
@@ -625,7 +624,7 @@ class MyView < SlackRubyBot::MVC::View::Base
625
624
 
626
625
  def react_thumbsup
627
626
  client.web_client.reactions_add(
628
- name: :thumbs_up,
627
+ name: :thumbsup,
629
628
  channel: data.channel,
630
629
  timestamp: data.ts,
631
630
  as_user: true)
@@ -633,7 +632,7 @@ class MyView < SlackRubyBot::MVC::View::Base
633
632
 
634
633
  def react_thumbsdown
635
634
  client.web_client.reactions_remove(
636
- name: :thumbs_up,
635
+ name: :thumbsup,
637
636
  channel: data.channel,
638
637
  timestamp: data.ts,
639
638
  as_user: true)
@@ -652,14 +651,17 @@ Again, the View will have access to the most up to date `client`, `data`, and `m
652
651
 
653
652
  View methods are not matched to routes, so there is no restriction on how to name methods as there is in Controllers.
654
653
 
655
- ### RSpec Shared Behaviors
654
+ ### Testing
655
+
656
+ #### RSpec Shared Behaviors
656
657
 
657
- Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in your RSpec tests.
658
+ Slack-ruby-bot comes with a number of shared RSpec behaviors that can be used in your RSpec tests.
658
659
 
659
660
  * [behaves like a slack bot](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb): A bot quacks like a Slack Ruby bot.
660
661
  * [respond with slack message](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb): The bot responds with a message.
661
662
  * [respond with slack messages](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb): The bot responds with a multiple messages.
662
663
  * [respond with error](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb): An exception is raised inside a bot command.
664
+ * [start typing](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb): The bot calls `client.start_typing`.
663
665
 
664
666
  Require `slack-ruby-bot/rspec` in your `spec_helper.rb` along with the following dependencies in Gemfile.
665
667
 
@@ -672,6 +674,72 @@ group :development, :test do
672
674
  end
673
675
  ```
674
676
 
677
+ Use the `respond_with_slack_message` matcher.
678
+
679
+ ```ruby
680
+ describe SlackRubyBot::Commands do
681
+ it 'responds with any message' do
682
+ expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message
683
+ end
684
+ it 'says hi' do
685
+ expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message('hi')
686
+ end
687
+ end
688
+ ```
689
+
690
+ Use the `respond_with_slack_messages` matcher for multiple messages.
691
+
692
+ ```ruby
693
+ describe SlackRubyBot::Commands do
694
+ it 'responds with more than one message' do
695
+ expect(message: "#{SlackRubyBot.config.user} count").to respond_with_slack_messages
696
+ end
697
+ it 'says one and two' do
698
+ expect(message: "#{SlackRubyBot.config.user} count").to respond_with_slack_messages(['one', 'two'])
699
+ end
700
+ end
701
+ ```
702
+
703
+ Message matchers support regular expressions.
704
+
705
+ ```ruby
706
+ describe SlackRubyBot::Commands do
707
+ it 'says hi' do
708
+ expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message(/hi/)
709
+ end
710
+ end
711
+ ```
712
+
713
+ Check that the bot called `client.start_typing(channel: 'channel')`.
714
+
715
+ ```ruby
716
+ describe SlackRubyBot::Commands do
717
+ it 'starts typing on channel' do
718
+ expect(message: "#{SlackRubyBot.config.user} hi").to start_typing(channel: 'channel')
719
+ end
720
+ end
721
+ ```
722
+
723
+ #### Testing Lower Level Messages
724
+
725
+ You can test client behavior at a lower level by fetching the message hook. The following example expects a bot command to call `client.typing(channel: data.channel)`.
726
+
727
+ ```ruby
728
+ describe SlackRubyBot::Commands do
729
+ let(:app) { Server.new }
730
+ let(:client) { app.send(:client) }
731
+ let(:message_hook) { SlackRubyBot::Hooks::Message.new }
732
+ it 'receives a typing event' do
733
+ expect(client).to receive(:typing)
734
+ message_hook.call(
735
+ client,
736
+ Hashie::Mash.new(text: "#{SlackRubyBot.config.user} type something", channel: 'channel')
737
+ )
738
+ end
739
+ end
740
+ end
741
+ ```
742
+
675
743
  ### Useful Libraries
676
744
 
677
745
  * [newrelic-slack-ruby-bot](https://github.com/dblock/newrelic-slack-ruby-bot): NewRelic instrumentation for slack-ruby-bot.
@@ -686,6 +754,6 @@ See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING
686
754
 
687
755
  ## Copyright and License
688
756
 
689
- Copyright (c) 2015-2016, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
757
+ Copyright (c) 2015-2020, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
690
758
 
691
759
  This project is licensed under the [MIT License](LICENSE.md).
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  require 'bundler/gem_tasks'