slack-ruby-bot 0.9.0 → 0.10.0

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: d81a287c11826ef682f08066d61ea77084f30fac
4
- data.tar.gz: ad1bca7b36da88557f9ee1b50acb1f4f929073a4
3
+ metadata.gz: d8e23b1dde8a7cb5147d728f4a0269e36f91fb27
4
+ data.tar.gz: b5355a6b7a7cf15868390e97c0aa423881373f6d
5
5
  SHA512:
6
- metadata.gz: cfd33b6f5f6e5121d88fb74a24525ce792002e4cb1cf16b4ad36ed242f75df6cfcf7ed055899e61b1d9a2d8a9cdd58d3c85ec41f5894df3cc6dca20c7056dc1f
7
- data.tar.gz: 855abd25109430b68e93a7bd1d3f21fc7f5ae54919ea0419a22ce5ecf6624ea35b9eaeed504babc368128077b72df1bbe09216930e971cbcdeb60f5a032f4a57
6
+ metadata.gz: 726e80f25e3bc5310298205bdea44759b830974a87d7f0723c444ee956113a40d9fdf67c6ca2a9f21138379e28c0cea6e38e3d5efa3796d2334f0f27e8fb1e40
7
+ data.tar.gz: 9235ebff49dc787ab29514b8c2351fbbad318a097a144168ac18d768b2aeceb743ec4d62767cf5c76d9f7063f56123b6288c530cf8a1b89176c871a963f76c6d
data/.rubocop_todo.yml CHANGED
@@ -1,5 +1,6 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2016-02-09 15:33:27 -0500 using RuboCop version 0.32.1.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-09-24 09:10:21 -0400 using RuboCop version 0.38.0.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
@@ -7,48 +8,48 @@
7
8
 
8
9
  # Offense count: 1
9
10
  Lint/HandleExceptions:
10
- Enabled: false
11
+ Exclude:
12
+ - 'lib/initializers/giphy.rb'
11
13
 
12
- # Offense count: 6
14
+ # Offense count: 5
13
15
  Metrics/AbcSize:
14
- Max: 42
15
-
16
- # Offense count: 1
17
- # Configuration parameters: CountComments.
18
- Metrics/ClassLength:
19
- Max: 102
16
+ Max: 36
20
17
 
21
18
  # Offense count: 2
22
19
  Metrics/CyclomaticComplexity:
23
- Max: 12
20
+ Max: 11
24
21
 
25
- # Offense count: 130
26
- # Configuration parameters: AllowURI, URISchemes.
22
+ # Offense count: 156
23
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
24
+ # URISchemes: http, https
27
25
  Metrics/LineLength:
28
- Max: 158
26
+ Max: 147
29
27
 
30
- # Offense count: 7
28
+ # Offense count: 6
31
29
  # Configuration parameters: CountComments.
32
30
  Metrics/MethodLength:
33
31
  Max: 27
34
32
 
35
33
  # Offense count: 2
36
34
  Metrics/PerceivedComplexity:
37
- Max: 12
35
+ Max: 11
38
36
 
39
- # Offense count: 20
37
+ # Offense count: 26
40
38
  Style/Documentation:
41
39
  Enabled: false
42
40
 
43
- # Offense count: 3
41
+ # Offense count: 1
44
42
  Style/DoubleNegation:
45
- Enabled: false
43
+ Exclude:
44
+ - 'lib/slack-ruby-bot/commands/base.rb'
46
45
 
47
46
  # Offense count: 1
48
- # Configuration parameters: Exclude.
47
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
49
48
  Style/FileName:
50
- Enabled: false
49
+ Exclude:
50
+ - 'lib/slack-ruby-bot.rb'
51
51
 
52
52
  # Offense count: 1
53
53
  Style/ModuleFunction:
54
- Enabled: false
54
+ Exclude:
55
+ - 'lib/slack-ruby-bot/config.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 0.10.0 (2/9/2017)
2
+
3
+ * [#111](https://github.com/slack-ruby/slack-ruby-bot/pull/111): Default keyword for GIFs in invalid commands has been changed from `idiot` to `understand` - [@dblock](https://github.com/dblock).
4
+ * [#98](https://github.com/slack-ruby/slack-ruby-bot/pull/98): Fixed a couple of problems in TUTORIAL.md - [@edruder](https://github.com/edruder).
5
+ * [#95](https://github.com/slack-ruby/slack-ruby-bot/pull/95): Log team name and ID on successful connection - [@dblock](https://github.com/dblock).
6
+ * [#94](https://github.com/slack-ruby/slack-ruby-bot/pull/94): Use the slack-ruby-danger gem - [@dblock](https://github.com/dblock).
7
+ * [#86](https://github.com/dblock/slack-ruby-bot/pull/86): Fix: help statements from classes that do not directly inherit from `Base` appear in `bot help` - [@maclover7](https://github.com/maclover7).
8
+ * [#96](https://github.com/slack-ruby/slack-ruby-bot/pull/96): Support help statements in anonymous command and bot classes - [@dblock](https://github.com/dblock).
9
+ * [#75](https://github.com/slack-ruby/slack-ruby-bot/pull/101): Fix: Guarantee order of commands based on load order - [@gconklin](https://github.com/gconklin).
10
+
1
11
  ### 0.9.0 (8/29/2016)
2
12
 
3
13
  * [#89](https://github.com/slack-ruby/slack-ruby-bot/pull/89): Drop giphy dependency - [@tmsrjs](https://github.com/tmsrjs).
data/Dangerfile CHANGED
@@ -1 +1 @@
1
- # inherits from https://github.com/slack-ruby/danger
1
+ danger.import_dangerfile(gem: 'slack-ruby-danger')
data/Gemfile CHANGED
@@ -4,4 +4,7 @@ gemspec
4
4
 
5
5
  gem ENV['CONCURRENCY'], require: false if ENV.key?('CONCURRENCY')
6
6
  gem 'giphy', require: false if ENV.key?('WITH_GIPHY')
7
- gem 'danger', '~> 2.0'
7
+
8
+ group :test do
9
+ gem 'slack-ruby-danger', '~> 0.1.0', require: false
10
+ end
data/README.md CHANGED
@@ -19,7 +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. 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, 0.10.0. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
23
23
 
24
24
  ## Usage
25
25
 
data/TUTORIAL.md CHANGED
@@ -19,6 +19,7 @@ gem 'slack-ruby-bot'
19
19
  gem 'puma'
20
20
  gem 'sinatra'
21
21
  gem 'dotenv'
22
+ gem 'celluloid-io'
22
23
 
23
24
  group :development, :test do
24
25
  gem 'rake'
@@ -172,15 +173,18 @@ require 'slack-mathbot'
172
173
 
173
174
  #### Test the Bot Application
174
175
 
175
- Create a test for the bot application itself in `spec/slack-mathbot/app_spec.rb`.
176
+ Create a test for the bot application itself in `spec/slack-mathbot/bot_spec.rb`.
176
177
 
177
178
  ```ruby
178
179
  require 'spec_helper'
179
180
 
180
- describe SlackMathbot::App do
181
+ describe SlackMathbot::Bot do
181
182
  def app
182
183
  SlackMathbot::Bot.instance
183
184
  end
185
+
186
+ subject { app }
187
+
184
188
  it_behaves_like 'a slack ruby bot'
185
189
  end
186
190
  ```
@@ -196,6 +200,9 @@ describe SlackMathbot::Commands::Calculate do
196
200
  def app
197
201
  SlackMathbot::Bot.instance
198
202
  end
203
+
204
+ subject { app }
205
+
199
206
  it 'returns 4' do
200
207
  expect(message: "#{SlackRubyBot.config.user} calculate 2+2", channel: 'channel').to respond_with_slack_message('4')
201
208
  end
@@ -6,4 +6,6 @@ class Bot < SlackRubyBot::Bot
6
6
  end
7
7
  end
8
8
 
9
+ SlackRubyBot::Client.logger.level = Logger::WARN
10
+
9
11
  Bot.run
@@ -11,7 +11,7 @@ module SlackRubyBot
11
11
  end
12
12
 
13
13
  def self.call(client, data, _match)
14
- client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'idiot')
14
+ client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
15
15
  end
16
16
  end
17
17
  end
@@ -5,6 +5,13 @@ module SlackRubyBot
5
5
  class_attribute :routes
6
6
 
7
7
  class << self
8
+ attr_reader :command_classes
9
+
10
+ def inherited(subclass)
11
+ @command_classes ||= []
12
+ @command_classes << subclass
13
+ end
14
+
8
15
  def send_message(client, channel, text, options = {})
9
16
  logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
10
17
  if text && !text.length.empty?
@@ -25,7 +32,7 @@ module SlackRubyBot
25
32
  end
26
33
 
27
34
  def help(&block)
28
- CommandsHelper.instance.capture_help(name, &block)
35
+ CommandsHelper.instance.capture_help(self, &block)
29
36
  end
30
37
 
31
38
  def default_command_name
@@ -3,10 +3,10 @@ module SlackRubyBot
3
3
  module Help
4
4
  class Attrs
5
5
  attr_accessor :command_name, :command_desc, :command_long_desc
6
- attr_reader :class_name, :commands
6
+ attr_reader :klass, :commands
7
7
 
8
- def initialize(class_name)
9
- @class_name = class_name
8
+ def initialize(klass)
9
+ @klass = klass
10
10
  @commands = []
11
11
  end
12
12
 
@@ -23,7 +23,7 @@ module SlackRubyBot
23
23
  end
24
24
 
25
25
  def command(title, &block)
26
- @commands << self.class.new(class_name).tap do |k|
26
+ @commands << self.class.new(klass).tap do |k|
27
27
  k.title(title)
28
28
  k.instance_eval(&block)
29
29
  end
@@ -4,7 +4,7 @@ module SlackRubyBot
4
4
  match(/^(?<bot>\S*)[\s]*(?<expression>.*)$/)
5
5
 
6
6
  def self.call(client, data, _match)
7
- client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'idiot')
7
+ client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
8
8
  end
9
9
  end
10
10
  end
@@ -9,7 +9,7 @@ module SlackRubyBot
9
9
 
10
10
  def call(client, _data)
11
11
  return unless client && client.team
12
- logger.info "Successfully connected to https://#{client.team.domain}.slack.com."
12
+ logger.info "Successfully connected team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com."
13
13
  end
14
14
  end
15
15
  end
@@ -26,7 +26,7 @@ module SlackRubyBot
26
26
  # @return [Array] Descendants of SlackRubyBot::Commands::Base.
27
27
  #
28
28
  def command_classes
29
- SlackRubyBot::Commands::Base.descendants
29
+ SlackRubyBot::Commands::Base.command_classes
30
30
  end
31
31
 
32
32
  #
@@ -10,8 +10,8 @@ module SlackRubyBot
10
10
  @commands_help_attrs = []
11
11
  end
12
12
 
13
- def capture_help(class_name, &block)
14
- k = Commands::Help::Attrs.new(class_name)
13
+ def capture_help(klass, &block)
14
+ k = Commands::Help::Attrs.new(klass)
15
15
  k.instance_eval(&block)
16
16
  @commands_help_attrs << k
17
17
  end
@@ -66,11 +66,11 @@ module SlackRubyBot
66
66
  end
67
67
 
68
68
  def bot_help_attrs
69
- commands_help_attrs.select { |k| k.class_name.constantize.superclass == SlackRubyBot::Bot }
69
+ commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Bot) }
70
70
  end
71
71
 
72
72
  def other_commands_help_attrs
73
- commands_help_attrs.select { |k| k.class_name.constantize.superclass == SlackRubyBot::Commands::Base }
73
+ commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Commands::Base) && !k.klass.ancestors.include?(SlackRubyBot::Bot) }
74
74
  end
75
75
  end
76
76
  end
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot::Commands::Base do
4
+ let! :command1 do
5
+ Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'command'
7
+
8
+ def self.call(client, data, match)
9
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
10
+ end
11
+ end
12
+ end
13
+
14
+ let! :command2 do
15
+ Class.new(SlackRubyBot::Commands::Base) do
16
+ command 'command'
17
+
18
+ def self.call(client, data, match)
19
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
20
+ end
21
+ end
22
+ end
23
+
24
+ def app
25
+ SlackRubyBot::App.new
26
+ end
27
+
28
+ describe '#command_classes' do
29
+ it 'returns all registered command classes' do
30
+ expect(SlackRubyBot::Commands::Base.command_classes).to include command1
31
+ expect(SlackRubyBot::Commands::Base.command_classes).to include command2
32
+ end
33
+
34
+ it 'returns command1 before command2' do
35
+ command_classes = SlackRubyBot::Commands::Base.command_classes
36
+ expect(command_classes.find_index(command1)).to be < command_classes.find_index(command2)
37
+ end
38
+ end
39
+ end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SlackRubyBot::CommandsHelper do
4
- let(:bot_class_name) { 'Testing::WeatherBot' }
5
- let(:command_class_name) { 'Testing::HelloCommand' }
4
+ let(:bot_class) { Testing::WeatherBot }
5
+ let(:command_class) { Testing::HelloCommand }
6
6
  let(:commands_helper) { described_class.instance }
7
7
 
8
8
  describe '#capture_help' do
9
9
  let(:help_attrs) { commands_helper.commands_help_attrs }
10
- let(:bot_help_attrs) { help_attrs.find { |k| k.class_name == bot_class_name } }
11
- let(:command_help_attrs) { help_attrs.find { |k| k.class_name == command_class_name } }
10
+ let(:bot_help_attrs) { help_attrs.find { |k| k.klass == bot_class } }
11
+ let(:command_help_attrs) { help_attrs.find { |k| k.klass == command_class } }
12
12
 
13
13
  it 'should save bot class name' do
14
14
  expect(bot_help_attrs).to be
@@ -62,7 +62,8 @@ describe SlackRubyBot::CommandsHelper do
62
62
  end
63
63
 
64
64
  describe '#bot_desc_and_commands' do
65
- let(:bot_desc) { commands_helper.bot_desc_and_commands.first }
65
+ let(:bot_desc_and_commands) { commands_helper.bot_desc_and_commands }
66
+ let(:bot_desc) { bot_desc_and_commands.first }
66
67
 
67
68
  it 'returns bot name and description' do
68
69
  expect(bot_desc).to include('*Weather Bot* - This bot tells you the weather.')
@@ -81,15 +82,43 @@ describe SlackRubyBot::CommandsHelper do
81
82
  it 'do not show description for command without description' do
82
83
  expect(bot_desc).to include("*command_without_description*\n")
83
84
  end
85
+
86
+ context 'subclasses' do
87
+ let(:another_bot_base) { Class.new(SlackRubyBot::Bot) }
88
+ let!(:another_bot) do
89
+ Class.new(another_bot_base) do
90
+ help do
91
+ title 'Creating your own base class works too!'
92
+ end
93
+ end
94
+ end
95
+
96
+ it 'expose help commands' do
97
+ expect(bot_desc_and_commands).to include("*Creating your own base class works too!*\n\n*Commands:*\n")
98
+ end
99
+ end
84
100
  end
85
101
 
86
102
  describe '#other_commands_descs' do
87
- let(:commands_desc) { commands_helper.other_commands_descs }
88
- let(:hello_command_desc) { commands_desc.find { |desc| desc =~ /\*hello\*/ } }
103
+ let(:another_command_base) { Class.new(SlackRubyBot::Commands::Base) }
104
+ let!(:another_command) do
105
+ Class.new(another_command_base) do
106
+ help do
107
+ title 'Creating your own base class works too!'
108
+ end
109
+ end
110
+ end
111
+
112
+ let(:other_commands_descs) { commands_helper.other_commands_descs }
113
+ let(:hello_command_desc) { other_commands_descs.find { |desc| desc =~ /\*hello\*/ } }
89
114
 
90
115
  it 'returns command name and description' do
91
116
  expect(hello_command_desc).to eq('*hello* - Says hello.')
92
117
  end
118
+
119
+ it 'includes commands who do not directly inherit from provided base class' do
120
+ expect(other_commands_descs).to include('*Creating your own base class works too!*')
121
+ end
93
122
  end
94
123
 
95
124
  describe '#command_full_desc' do
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -204,6 +204,7 @@ files:
204
204
  - spec/slack-ruby-bot/commands/aliases_spec.rb
205
205
  - spec/slack-ruby-bot/commands/bot_message_spec.rb
206
206
  - spec/slack-ruby-bot/commands/bot_spec.rb
207
+ - spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
207
208
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
208
209
  - spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
209
210
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
@@ -267,6 +268,7 @@ test_files:
267
268
  - spec/slack-ruby-bot/commands/aliases_spec.rb
268
269
  - spec/slack-ruby-bot/commands/bot_message_spec.rb
269
270
  - spec/slack-ruby-bot/commands/bot_spec.rb
271
+ - spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
270
272
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
271
273
  - spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
272
274
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb