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.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.rubocop.yml +14 -1
- data/.rubocop_todo.yml +13 -36
- data/.travis.yml +7 -5
- data/CHANGELOG.md +9 -0
- data/DEPLOYMENT.md +61 -5
- data/Dangerfile +2 -0
- data/Gemfile +10 -3
- data/LICENSE.md +1 -1
- data/README.md +78 -10
- data/Rakefile +2 -0
- data/TUTORIAL.md +23 -0
- data/UPGRADING.md +8 -0
- data/examples/inventory/Gemfile +2 -0
- data/examples/inventory/inventorybot.rb +5 -1
- data/examples/market/Gemfile +4 -3
- data/examples/market/marketbot.rb +22 -15
- data/examples/minimal/Gemfile +2 -0
- data/examples/minimal/pongbot.rb +2 -0
- data/examples/weather/Gemfile +2 -0
- data/examples/weather/weatherbot.rb +2 -0
- data/lib/config/application.rb +4 -2
- data/lib/config/boot.rb +2 -0
- data/lib/config/environment.rb +3 -1
- data/lib/initializers/giphy.rb +2 -0
- data/lib/initializers/giphy_client.rb +2 -0
- data/lib/slack-ruby-bot.rb +3 -1
- data/lib/slack-ruby-bot/about.rb +3 -1
- data/lib/slack-ruby-bot/app.rb +2 -0
- data/lib/slack-ruby-bot/bot.rb +2 -0
- data/lib/slack-ruby-bot/client.rb +7 -4
- data/lib/slack-ruby-bot/commands.rb +2 -0
- data/lib/slack-ruby-bot/commands/about.rb +2 -0
- data/lib/slack-ruby-bot/commands/base.rb +12 -1
- data/lib/slack-ruby-bot/commands/help.rb +9 -7
- data/lib/slack-ruby-bot/commands/hi.rb +2 -0
- data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
- data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
- data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
- data/lib/slack-ruby-bot/commands/unknown.rb +2 -0
- data/lib/slack-ruby-bot/config.rb +3 -0
- data/lib/slack-ruby-bot/hooks.rb +2 -0
- data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
- data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -0
- data/lib/slack-ruby-bot/hooks/message.rb +5 -2
- data/lib/slack-ruby-bot/hooks/set.rb +3 -1
- data/lib/slack-ruby-bot/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
- data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
- data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
- data/lib/slack-ruby-bot/rspec.rb +3 -1
- data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -5
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +16 -13
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +27 -18
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
- data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/vcr.rb +2 -0
- data/lib/slack-ruby-bot/server.rb +2 -0
- data/lib/slack-ruby-bot/support/loggable.rb +2 -0
- data/lib/slack-ruby-bot/version.rb +3 -1
- data/lib/slack_ruby_bot.rb +2 -0
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-bot.gemspec +5 -2
- data/spec/slack-ruby-bot/app_spec.rb +2 -0
- data/spec/slack-ruby-bot/client_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/about_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/aliases_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/attachment_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
- data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/send_gif_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/attrs_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/help_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -0
- data/spec/slack-ruby-bot/config_spec.rb +2 -0
- data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
- data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -0
- data/spec/slack-ruby-bot/hooks/message_spec.rb +3 -1
- data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
- data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +2 -0
- data/spec/slack-ruby-bot/initializers/giphy_spec.rb +2 -0
- data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
- data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
- data/spec/slack-ruby-bot/server_spec.rb +2 -0
- data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
- data/spec/slack-ruby-bot/version_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +12 -8
- data/screenshots/register-bot.png +0 -0
|
@@ -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 =
|
|
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
|
|
@@ -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::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'
|
|
10
|
+
Hashie::Mash.new(text: 'message')
|
|
9
11
|
)
|
|
10
12
|
end
|
|
11
13
|
end
|
|
@@ -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}") }
|