slack-ruby-bot 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12c173de864218ce41d7115da1a9c6ded20649eb
4
- data.tar.gz: 01733d1afa189753bd3bc338a9508f138a69dbcb
3
+ metadata.gz: e3a131c7f852f22c4039f8a40e25a7a914d40a0f
4
+ data.tar.gz: 1f31b3ef7089c492712d5cc5bc0edec6947a7e5a
5
5
  SHA512:
6
- metadata.gz: e834c192faaa6922e02c536c6fb8620fe20d32bcb58be48dea83c9f6283b75c6cbe738e2422ee67830f928d10979fbdd03cc87a8946cc565501c839c7d659dba
7
- data.tar.gz: da3d808d4863af50cc8cdfc689ead159d013fc4955428d6c1e6cc6069417817112a870da7a1a8e420de283da4579c219569178848f4f3c05d64aa20abbc03bdc
6
+ metadata.gz: 6d721d75a37a031b6e12003f47a4ba68e7e60be61abd26f2b76999768448b18ef8ab7bc01394aab7047978ef7ee5845ea79a11540232fe7abc2d508c44076188
7
+ data.tar.gz: '09ca8c66e5ffe883faa832208fe341379131ed710f7ed6945959564d92ce2a9e8ed2196f96a262aace493b043c7d4852f3f6d25bc82dc5e698c754ee7b869328'
@@ -1,22 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-06-16 13:07:42 -0500 using RuboCop version 0.48.1.
3
+ # on 2017-10-15 13:34:54 -0700 using RuboCop version 0.38.0.
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: 4
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
12
- # Include: **/Gemfile, **/gems.rb
13
- Bundler/OrderedGems:
14
- Exclude:
15
- - 'examples/inventory/Gemfile'
16
- - 'examples/market/Gemfile'
17
- - 'examples/minimal/Gemfile'
18
- - 'examples/weather/Gemfile'
19
-
20
9
  # Offense count: 1
21
10
  Lint/HandleExceptions:
22
11
  Exclude:
@@ -24,19 +13,19 @@ Lint/HandleExceptions:
24
13
 
25
14
  # Offense count: 6
26
15
  Metrics/AbcSize:
27
- Max: 36
16
+ Max: 40
28
17
 
29
- # Offense count: 21
30
- # Configuration parameters: CountComments, ExcludedMethods.
31
- Metrics/BlockLength:
32
- Max: 120
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 104
33
22
 
34
23
  # Offense count: 2
35
24
  Metrics/CyclomaticComplexity:
36
25
  Max: 13
37
26
 
38
- # Offense count: 199
39
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
27
+ # Offense count: 218
28
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
40
29
  # URISchemes: http, https
41
30
  Metrics/LineLength:
42
31
  Max: 147
@@ -44,13 +33,13 @@ Metrics/LineLength:
44
33
  # Offense count: 10
45
34
  # Configuration parameters: CountComments.
46
35
  Metrics/MethodLength:
47
- Max: 27
36
+ Max: 19
48
37
 
49
38
  # Offense count: 2
50
39
  Metrics/PerceivedComplexity:
51
40
  Max: 13
52
41
 
53
- # Offense count: 30
42
+ # Offense count: 31
54
43
  Style/Documentation:
55
44
  Enabled: false
56
45
 
@@ -59,58 +48,13 @@ Style/DoubleNegation:
59
48
  Exclude:
60
49
  - 'lib/slack-ruby-bot/commands/base.rb'
61
50
 
62
- # Offense count: 2
63
- # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
64
- # 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
51
+ # Offense count: 1
52
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
65
53
  Style/FileName:
66
54
  Exclude:
67
- - 'Dangerfile'
68
55
  - 'lib/slack-ruby-bot.rb'
69
56
 
70
- # Offense count: 2
71
- # Cop supports --auto-correct.
72
- # Configuration parameters: EnforcedStyle, SupportedStyles.
73
- # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
74
- Style/IndentHeredoc:
75
- Exclude:
76
- - 'lib/slack-ruby-bot/commands/help.rb'
77
- - 'spec/slack-ruby-bot/commands/help_spec.rb'
78
-
79
57
  # Offense count: 1
80
- # Configuration parameters: EnforcedStyle, SupportedStyles.
81
- # SupportedStyles: module_function, extend_self
82
58
  Style/ModuleFunction:
83
59
  Exclude:
84
60
  - 'lib/slack-ruby-bot/config.rb'
85
-
86
- # Offense count: 3
87
- # Cop supports --auto-correct.
88
- Style/MultilineIfModifier:
89
- Exclude:
90
- - 'lib/slack-ruby-bot/app.rb'
91
- - 'lib/slack-ruby-bot/client.rb'
92
- - 'lib/slack-ruby-bot/commands/base.rb'
93
-
94
- # Offense count: 5
95
- # Cop supports --auto-correct.
96
- # Configuration parameters: PreferredDelimiters.
97
- Style/PercentLiteralDelimiters:
98
- Exclude:
99
- - 'lib/slack-ruby-bot/server.rb'
100
- - 'spec/slack-ruby-bot/commands/aliases_spec.rb'
101
- - 'spec/slack-ruby-bot/hooks/hook_support_spec.rb'
102
- - 'spec/slack-ruby-bot/server_spec.rb'
103
-
104
- # Offense count: 3
105
- # Cop supports --auto-correct.
106
- # Configuration parameters: SupportedStyles.
107
- # SupportedStyles: percent, brackets
108
- Style/SymbolArray:
109
- EnforcedStyle: brackets
110
-
111
- # Offense count: 2
112
- # Configuration parameters: EnforcedStyle, SupportedStyles.
113
- # SupportedStyles: snake_case, normalcase, non_integer
114
- Style/VariableNumber:
115
- Exclude:
116
- - 'spec/slack-ruby-bot/hooks/set_spec.rb'
@@ -1,3 +1,11 @@
1
+ ### 0.10.5 (10/15/2017)
2
+
3
+ * Refactored `SlackRubyBot::MVC::Controller::Base`, consolidated ivar handling, centralized object allocations and DRYed up the code - [@chuckremes](https://github.com/chuckremes).
4
+ * [#157](https://github.com/slack-ruby/slack-ruby-bot/pull/157): Added `respond_with_slack_messages` expectation - [@gcraig99](https://github.com/gcraig99).
5
+ * [#160](https://github.com/slack-ruby/slack-ruby-bot/pull/160): Fixed `respond_with_slack_message(s)` expectation failures - [@gcraig99](https://github.com/gcraig99).
6
+ * [#163](https://github.com/slack-ruby/slack-ruby-bot/pull/163): Allow `command` to accept regular expressions - [@kstole](https://github.com/kstole).
7
+ * [#166](https://github.com/slack-ruby/slack-ruby-bot/pull/166): Allow special characters and capitals in bot aliases - [@kstole](https://github.com/kstole).
8
+
1
9
  ### 0.10.4 (07/05/2017)
2
10
 
3
11
  * [#149](https://github.com/slack-ruby/slack-ruby-bot/pull/149): Add `logger` configuration to set a custom logger - [@upscent](https://github.com/upscent).
data/README.md CHANGED
@@ -82,6 +82,16 @@ end
82
82
 
83
83
  Command match data includes `match['bot']`, `match['command']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` and `SlackRubyBot::Config.user_id` values obtained when the bot starts.
84
84
 
85
+ The `command` method can take strings, which will have be escaped with `Regexp.escape`, and regular expressions.
86
+
87
+ ```ruby
88
+ class CallBot < SlackRubyBot::Bot
89
+ command 'string with spaces', /some\s*regex+\?*/ do |client, data, match|
90
+ client.say(channel: data.channel, text: match['command'])
91
+ end
92
+ end
93
+ ```
94
+
85
95
  Operators are 1-letter long and are similar to commands. They don't require addressing a bot nor separating an operator from its arguments. The following class responds to `=2+2`.
86
96
 
87
97
  ```ruby
@@ -547,6 +557,7 @@ Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in
547
557
 
548
558
  * [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.
549
559
  * [respond with slack message](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb): The bot responds with a message.
560
+ * [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.
550
561
  * [respond with error](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb): An exception is raised inside a bot command.
551
562
 
552
563
  Require `slack-ruby-bot/rspec` in your `spec_helper.rb` along with the following dependencies in Gemfile.
@@ -14,8 +14,8 @@ module SlackRubyBot
14
14
  [
15
15
  SlackRubyBot::Config.user,
16
16
  self.self ? self.self.name : nil,
17
- aliases,
18
- SlackRubyBot::Config.aliases,
17
+ aliases ? aliases.map(&:downcase) : nil,
18
+ SlackRubyBot::Config.aliases ? SlackRubyBot::Config.aliases.map(&:downcase) : nil,
19
19
  self.self && self.self.id ? "<@#{self.self.id.downcase}>" : nil,
20
20
  SlackRubyBot::Config.user_id ? "<@#{SlackRubyBot::Config.user_id.downcase}>" : nil,
21
21
  self.self && self.self.id ? "<@#{self.self.id.downcase}>:" : nil,
@@ -2,7 +2,7 @@ module SlackRubyBot
2
2
  module Commands
3
3
  class Default < Base
4
4
  command 'about'
5
- match(/^(?<bot>[[:alnum:][:punct:]@<>]*)$/u)
5
+ match(/^#{bot_matcher}$/u)
6
6
 
7
7
  def self.call(client, data, _match)
8
8
  client.say(channel: data.channel, text: SlackRubyBot::ABOUT, gif: 'selfie')
@@ -35,7 +35,7 @@ module SlackRubyBot
35
35
  CommandsHelper.instance.capture_help(self, &block)
36
36
  end
37
37
 
38
- def default_command_name
38
+ def command_name_from_class
39
39
  name ? name.split(':').last.downcase : object_id.to_s
40
40
  end
41
41
 
@@ -45,14 +45,14 @@ module SlackRubyBot
45
45
  end
46
46
 
47
47
  def command(*values, &block)
48
- values = values.map { |value| Regexp.escape(value) }.join('|')
49
- match Regexp.new("^(?<bot>[[:alnum:][:punct:]@<>]*)[\\s]+(?<command>#{values})([\\s]+(?<expression>.*)|)$", Regexp::IGNORECASE), &block
48
+ values = values.map { |value| value.is_a?(Regexp) ? value.source : Regexp.escape(value) }.join('|')
49
+ match Regexp.new("^#{bot_matcher}[\\s]+(?<command>#{values})([\\s]+(?<expression>.*)|)$", Regexp::IGNORECASE), &block
50
50
  end
51
51
 
52
52
  def invoke(client, data)
53
53
  finalize_routes!
54
54
  expression, text = parse(client, data)
55
- called = false
55
+ return false unless expression
56
56
  routes.each_pair do |route, options|
57
57
  match_method = options[:match_method]
58
58
  case match_method
@@ -65,36 +65,42 @@ module SlackRubyBot
65
65
  match = expression.scan(route)
66
66
  next unless match.any?
67
67
  end
68
- called = true
69
- call = options[:call]
70
- if call
71
- call.call(client, data, match) if permitted?(client, data, match)
72
- elsif respond_to?(:call)
73
- send(:call, client, data, match) if permitted?(client, data, match)
74
- else
75
- raise NotImplementedError, data.text
76
- end
77
- break
78
- end if expression
79
- called
68
+ call_command(client, data, match, options[:block])
69
+ return true
70
+ end
71
+ false
80
72
  end
81
73
 
82
74
  def match(match, &block)
83
75
  self.routes ||= ActiveSupport::OrderedHash.new
84
- self.routes[match] = { match_method: :match, call: block }
76
+ self.routes[match] = { match_method: :match, block: block }
85
77
  end
86
78
 
87
79
  def scan(match, &block)
88
80
  self.routes ||= ActiveSupport::OrderedHash.new
89
- self.routes[match] = { match_method: :scan, call: block }
81
+ self.routes[match] = { match_method: :scan, block: block }
82
+ end
83
+
84
+ def bot_matcher
85
+ '(?<bot>\S*)'
90
86
  end
91
87
 
92
88
  private
93
89
 
90
+ def call_command(client, data, match, block)
91
+ if block
92
+ block.call(client, data, match) if permitted?(client, data, match)
93
+ elsif respond_to?(:call)
94
+ send(:call, client, data, match) if permitted?(client, data, match)
95
+ else
96
+ raise NotImplementedError, data.text
97
+ end
98
+ end
99
+
94
100
  def parse(client, data)
95
101
  text = data.text
96
102
  return text unless direct_message?(data) && message_from_another_user?(data)
97
- return text if bot_mentioned_in_message?(text, client.names)
103
+ return text if message_begins_with_bot_mention?(text, client.names)
98
104
  ["#{client.name} #{text}", text]
99
105
  end
100
106
 
@@ -106,14 +112,14 @@ module SlackRubyBot
106
112
  data.user && data.user != SlackRubyBot.config.user_id
107
113
  end
108
114
 
109
- def bot_mentioned_in_message?(text, bot_names)
115
+ def message_begins_with_bot_mention?(text, bot_names)
110
116
  bot_names = bot_names.join('|')
111
117
  !!text.downcase.match(/\A(#{bot_names})\s|\A(#{bot_names})\z/)
112
118
  end
113
119
 
114
120
  def finalize_routes!
115
121
  return if routes && routes.any?
116
- command default_command_name
122
+ command command_name_from_class
117
123
  end
118
124
 
119
125
  # Intended to be overridden by subclasses to hook in an
@@ -9,24 +9,31 @@ module SlackRubyBot
9
9
  alias abstract? abstract
10
10
 
11
11
  def controllers
12
- Base.instance_variable_get(:@controllers)
12
+ get_or_set_ivar(:@controllers, [])
13
13
  end
14
14
 
15
15
  def command_class
16
- Base.instance_variable_get(:@command_class)
16
+ get_or_set_ivar(:@command_class, Class.new(SlackRubyBot::Commands::Base))
17
17
  end
18
18
 
19
19
  def aliases
20
- Base.instance_variable_get(:@aliases)
20
+ get_or_set_ivar(:@aliases, Hash.new { |h, k| h[k] = [] })
21
+ end
22
+
23
+ def get_or_set_ivar(name, value)
24
+ unless (ivar = Base.instance_variable_get(name))
25
+ ivar = value
26
+ Base.instance_variable_set(name, ivar)
27
+ end
28
+ ivar
21
29
  end
22
30
 
23
31
  def reset!
24
32
  # Remove any earlier anonymous classes from prior calls so we don't leak them
25
33
  Commands::Base.command_classes.delete(Controller::Base.command_class) if Base.command_class
26
34
 
27
- # Create anonymous class to hold our #commands; required by SlackRubyBot::Commands::Base
28
- Base.instance_variable_set(:@command_class, Class.new(SlackRubyBot::Commands::Base))
29
- Base.instance_variable_set(:@controllers, [])
35
+ Base.instance_variable_set(:@command_class, nil)
36
+ Base.instance_variable_set(:@controllers, nil)
30
37
  end
31
38
 
32
39
  # Define a controller as abstract. See internal_methods for more
@@ -46,10 +53,7 @@ module SlackRubyBot
46
53
 
47
54
  def register_controller(controller)
48
55
  # Only used to keep a reference around so the instance object doesn't get garbage collected
49
- Base.instance_variable_set(:@controllers, []) unless controllers
50
- Base.instance_variable_set(:@aliases, Hash.new { |h, k| h[k] = [] }) unless aliases
51
- controller_ary = Base.instance_variable_get(:@controllers)
52
- controller_ary << controller
56
+ controllers << controller
53
57
  klass = controller.class
54
58
 
55
59
  methods = (klass.public_instance_methods(true) -
@@ -1,5 +1,33 @@
1
1
  ---
2
2
  http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://slack.com/api/rtm.connect
6
+ body:
7
+ string: token=token
8
+ response:
9
+ status:
10
+ code: 200
11
+ message: OK
12
+ body:
13
+ encoding: UTF-8
14
+ string: '{"ok":false,"error":"migration_in_progress"}'
15
+ http_version:
16
+ recorded_at: Tue, 28 Apr 2015 12:55:22 GMT
17
+ - request:
18
+ method: post
19
+ uri: https://slack.com/api/rtm.connect
20
+ body:
21
+ string: token=token
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ body:
27
+ encoding: UTF-8
28
+ string: '{"ok":false,"error":"unknown"}'
29
+ http_version:
30
+ recorded_at: Tue, 28 Apr 2015 12:55:22 GMT
3
31
  - request:
4
32
  method: post
5
33
  uri: https://slack.com/api/rtm.start
@@ -1,27 +1,33 @@
1
1
  require 'rspec/expectations'
2
-
3
2
  RSpec::Matchers.define :respond_with_slack_message do |expected|
3
+ include SlackRubyBot::SpecHelpers
4
4
  match do |actual|
5
- client = if respond_to?(:client)
6
- send(:client)
7
- else
8
- SlackRubyBot::Client.new
9
- end
5
+ client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new
6
+ def client.test_messages
7
+ @test_received_messages
8
+ end
9
+
10
+ def client.say(options = {})
11
+ super
12
+ @test_received_messages = @test_received_messages.nil? ? [] : @test_received_messages
13
+ @test_received_messages.push options
14
+ end
10
15
 
11
16
  message_command = SlackRubyBot::Hooks::Message.new
12
17
  channel, user, message = parse(actual)
13
18
 
14
19
  allow(Giphy).to receive(:random) if defined?(Giphy)
15
20
 
16
- expect(client).to receive(:message).with(channel: channel, text: expected)
21
+ allow(client).to receive(:message)
17
22
  message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user))
23
+ @messages = client.test_messages
24
+ expect(client).to have_received(:message).with(hash_including(channel: channel, text: expected)).once
18
25
  true
19
26
  end
20
27
 
21
- private
22
-
23
- def parse(actual)
24
- actual = { message: actual } unless actual.is_a?(Hash)
25
- [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]]
28
+ failure_message do |_actual|
29
+ message = "expected to receive message with text: #{expected} once,\n received:"
30
+ message += @messages.count.zero? ? 'No response messages received' : @messages.inspect
31
+ message
26
32
  end
27
33
  end
@@ -0,0 +1,38 @@
1
+ require 'rspec/expectations'
2
+ RSpec::Matchers.define :respond_with_slack_messages do |expected|
3
+ include SlackRubyBot::SpecHelpers
4
+ 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
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
16
+
17
+ message_command = SlackRubyBot::Hooks::Message.new
18
+ channel, user, message = parse(actual)
19
+
20
+ allow(Giphy).to receive(:random) if defined?(Giphy)
21
+
22
+ allow(client).to receive(:message)
23
+ message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user))
24
+ @messages = client.test_messages
25
+ @responses = []
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
+ true
30
+ end
31
+ 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)]
35
+ end
36
+ message
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module SlackRubyBot
2
+ module SpecHelpers
3
+ private
4
+
5
+ def parse(actual)
6
+ actual = { message: actual } unless actual.is_a?(Hash)
7
+ [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]]
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.10.4'.freeze
2
+ VERSION = '0.10.5'.freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  describe SlackRubyBot do
2
2
  def client
3
- SlackRubyBot::Client.new aliases: %w(:emoji: alias каспаров)
3
+ SlackRubyBot::Client.new aliases: %w[:emoji: alias каспаров B0?.@(*^$]
4
4
  end
5
5
  it 'responds to emoji' do
6
6
  expect(message: ':emoji: hi').to respond_with_slack_message('Hi <@user>!')
@@ -11,4 +11,7 @@ describe SlackRubyBot do
11
11
  it 'responds to a non-English alias' do
12
12
  expect(message: 'каспаров hi').to respond_with_slack_message('Hi <@user>!')
13
13
  end
14
+ it 'responds to an alias with special characters' do
15
+ expect(message: 'B0?.@(*^$ hi').to respond_with_slack_message('Hi <@user>!')
16
+ end
14
17
  end
@@ -38,7 +38,7 @@ describe SlackRubyBot::Commands::Base do
38
38
  command_classes = SlackRubyBot::Commands::Base.command_classes
39
39
  anon_class = Class.new(SlackRubyBot::Commands::Base)
40
40
  expect(command_classes).to include anon_class
41
- expect(command_classes.find { |obj| obj == anon_class }.object_id.to_s).to eq anon_class.default_command_name
41
+ expect(command_classes.find { |obj| obj == anon_class }.object_id.to_s).to eq anon_class.command_name_from_class
42
42
  end
43
43
  end
44
44
  end
@@ -0,0 +1,16 @@
1
+ describe SlackRubyBot::Commands do
2
+ let! :command do
3
+ Class.new(SlackRubyBot::Commands::Base) do
4
+ command(/some\s*regex+\?*/) do |client, data, match|
5
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
6
+ end
7
+ end
8
+ end
9
+ def app
10
+ SlackRubyBot::App.new
11
+ end
12
+ it 'handles regular expressions' do
13
+ expect(message: "#{SlackRubyBot.config.user} some regex works here").to respond_with_slack_message('some regex: works here')
14
+ expect(message: "#{SlackRubyBot.config.user} some RegEx?? yep").to respond_with_slack_message('some RegEx??: yep')
15
+ end
16
+ end
@@ -27,11 +27,11 @@ describe SlackRubyBot::Commands do
27
27
  end
28
28
  it 'checks that bot mentioned in message' do
29
29
  bot_names = ['rubybot', '<@deadbeef>', '<@deadbeef>:', 'rubybot:']
30
- expect(command.send(:bot_mentioned_in_message?, 'rubybot', bot_names)).to be true
31
- expect(command.send(:bot_mentioned_in_message?, 'rubybot ', bot_names)).to be true
32
- expect(command.send(:bot_mentioned_in_message?, 'rubybotbot', bot_names)).to be false
33
- expect(command.send(:bot_mentioned_in_message?, 'rubybot:', bot_names)).to be true
34
- expect(command.send(:bot_mentioned_in_message?, 'rubybot: ', bot_names)).to be true
35
- expect(command.send(:bot_mentioned_in_message?, 'rubybot:bot', bot_names)).to be false
30
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybot', bot_names)).to be true
31
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybot ', bot_names)).to be true
32
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybotbot', bot_names)).to be false
33
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybot:', bot_names)).to be true
34
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybot: ', bot_names)).to be true
35
+ expect(command.send(:message_begins_with_bot_mention?, 'rubybot:bot', bot_names)).to be false
36
36
  end
37
37
  end
@@ -0,0 +1,49 @@
1
+ describe RSpec do
2
+ let! :command do
3
+ Class.new(SlackRubyBot::Commands::Base) do
4
+ command 'single message with as_user' do |client, data, _match|
5
+ client.say(text: 'single response', channel: data.channel, as_user: true)
6
+ end
7
+ command 'single message' do |client, data, _match|
8
+ client.say(text: 'single response', channel: data.channel)
9
+ end
10
+ command 'respond 5 times' do |client, data, _match|
11
+ 5.times do |i|
12
+ client.say(text: "response #{i}", channel: data.channel)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def app
19
+ SlackRubyBot::App.new
20
+ end
21
+ it 'respond_with_single_message_using_regex_match' do
22
+ expect(message: "#{SlackRubyBot.config.user} single message")
23
+ .to respond_with_slack_message(/single response/i)
24
+ end
25
+ it 'respond_with_single_message_using_partial_regex_match' do
26
+ expect(message: "#{SlackRubyBot.config.user} single message")
27
+ .to respond_with_slack_message(/si[n|N]gle/)
28
+ end
29
+ it 'not_respond_with_single_message_using_bad_regex_match' do
30
+ expect(message: "#{SlackRubyBot.config.user} single message")
31
+ .not_to respond_with_slack_message(/si[g|G]gle/)
32
+ end
33
+ it 'respond_with_single_message_using_string_match' do
34
+ expect(message: "#{SlackRubyBot.config.user} single message")
35
+ .to respond_with_slack_message('single response')
36
+ end
37
+ it 'respond_with_single_message_using_regex_match_with_extra_args' do
38
+ expect(message: "#{SlackRubyBot.config.user} single message with as_user")
39
+ .to respond_with_slack_message(/single response/i)
40
+ end
41
+ it 'respond_with_multiple_messages_looking_for_single_match' do
42
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
43
+ .to respond_with_slack_message('response 1')
44
+ end
45
+ it 'respond_with_multiple_messages_no_match' do
46
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
47
+ .not_to respond_with_slack_message('response 7')
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ describe RSpec do
2
+ let! :command do
3
+ Class.new(SlackRubyBot::Commands::Base) do
4
+ command 'respond with as_user' do |client, data, _match|
5
+ 5.times do |i|
6
+ client.say(text: "response #{i}", channel: data.channel, as_user: true)
7
+ end
8
+ end
9
+ command 'respond 5 times' do |client, data, _match|
10
+ 5.times do |i|
11
+ client.say(text: "response #{i}", channel: data.channel)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ def app
18
+ SlackRubyBot::App.new
19
+ end
20
+
21
+ it 'respond_with_multiple_messages_using_regex_matches' do
22
+ expected_responses = []
23
+ 5.times { |i| expected_responses.push(/response #{i}/i) }
24
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
25
+ .to respond_with_slack_messages(expected_responses)
26
+ end
27
+ it 'respond_with_multiple_messages_using_string_matches' do
28
+ expected_responses = []
29
+ 5.times { |i| expected_responses.push("response #{i}") }
30
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
31
+ .to respond_with_slack_messages(expected_responses)
32
+ end
33
+ it 'not_respond_with_multiple_messages_using_string_matches' do
34
+ expected_responses = []
35
+ 6.times { |i| expected_responses.push("response #{i}") }
36
+ expect(message: "#{SlackRubyBot.config.user} respond 5 times")
37
+ .not_to respond_with_slack_messages(expected_responses)
38
+ end
39
+ it 'respond_with_multiple_messages_using_string_matches_with_extra_arg' do
40
+ expected_responses = []
41
+ 5.times { |i| expected_responses.push("response #{i}") }
42
+ expect(message: "#{SlackRubyBot.config.user} respond with as_user")
43
+ .to respond_with_slack_messages(expected_responses)
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -190,8 +190,10 @@ files:
190
190
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
191
191
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb
192
192
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb
193
+ - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb
193
194
  - lib/slack-ruby-bot/rspec/support/slack_api_key.rb
194
195
  - lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb
196
+ - lib/slack-ruby-bot/rspec/support/spec_helpers.rb
195
197
  - lib/slack-ruby-bot/rspec/support/vcr.rb
196
198
  - lib/slack-ruby-bot/server.rb
197
199
  - lib/slack-ruby-bot/support/commands_helper.rb
@@ -217,6 +219,7 @@ files:
217
219
  - spec/slack-ruby-bot/commands/commands_permitted_spec.rb
218
220
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
219
221
  - spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
222
+ - spec/slack-ruby-bot/commands/commands_regexp_spec.rb
220
223
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
221
224
  - spec/slack-ruby-bot/commands/commands_spec.rb
222
225
  - spec/slack-ruby-bot/commands/commands_with_block_spec.rb
@@ -243,6 +246,8 @@ files:
243
246
  - spec/slack-ruby-bot/hooks/set_spec.rb
244
247
  - spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb
245
248
  - spec/slack-ruby-bot/rspec/respond_with_error_spec.rb
249
+ - spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb
250
+ - spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb
246
251
  - spec/slack-ruby-bot/server_spec.rb
247
252
  - spec/slack-ruby-bot/support/commands_helper_spec.rb
248
253
  - spec/slack-ruby-bot/support/loggable_spec.rb
@@ -268,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
273
  version: 1.3.6
269
274
  requirements: []
270
275
  rubyforge_project:
271
- rubygems_version: 2.6.8
276
+ rubygems_version: 2.6.13
272
277
  signing_key:
273
278
  specification_version: 4
274
279
  summary: The easiest way to write a Slack bot in Ruby.
@@ -283,6 +288,7 @@ test_files:
283
288
  - spec/slack-ruby-bot/commands/commands_permitted_spec.rb
284
289
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
285
290
  - spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
291
+ - spec/slack-ruby-bot/commands/commands_regexp_spec.rb
286
292
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
287
293
  - spec/slack-ruby-bot/commands/commands_spec.rb
288
294
  - spec/slack-ruby-bot/commands/commands_with_block_spec.rb
@@ -309,6 +315,8 @@ test_files:
309
315
  - spec/slack-ruby-bot/hooks/set_spec.rb
310
316
  - spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb
311
317
  - spec/slack-ruby-bot/rspec/respond_with_error_spec.rb
318
+ - spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb
319
+ - spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb
312
320
  - spec/slack-ruby-bot/server_spec.rb
313
321
  - spec/slack-ruby-bot/support/commands_helper_spec.rb
314
322
  - spec/slack-ruby-bot/support/loggable_spec.rb