lita 4.5.0 → 4.8.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +6 -7
- data/Rakefile +0 -7
- data/lib/lita.rb +1 -0
- data/lib/lita/adapter.rb +8 -1
- data/lib/lita/adapters/test.rb +43 -0
- data/lib/lita/handler/chat_router.rb +2 -14
- data/lib/lita/handler/common.rb +13 -1
- data/lib/lita/handler/event_router.rb +5 -1
- data/lib/lita/handlers/info.rb +5 -1
- data/lib/lita/message.rb +6 -0
- data/lib/lita/robot.rb +4 -1
- data/lib/lita/rspec/handler.rb +29 -20
- data/lib/lita/template.rb +1 -1
- data/lib/lita/version.rb +1 -1
- data/lita.gemspec +13 -13
- data/script/ci +4 -0
- data/spec/lita/configuration_builder_spec.rb +9 -0
- data/spec/lita/handler/event_router_spec.rb +54 -2
- data/spec/lita/handler/http_router_spec.rb +1 -1
- data/spec/lita/handlers/info_spec.rb +1 -1
- data/spec/lita/message_spec.rb +8 -0
- data/spec/lita/robot_spec.rb +13 -0
- data/spec/lita/rspec_spec.rb +43 -0
- data/spec/lita_spec.rb +7 -0
- data/spec/spec_helper.rb +0 -5
- metadata +35 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f20cc77c412f1649c46ec2b8ffad7ebdf91310ec1c5985983faaabe8888f2c3f
|
4
|
+
data.tar.gz: 74d03bf2b6d3ce8b20ae84c3b56f20641a78a439a24bca26d55e952eadd0bc1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0926727362e120bb091d2f34721d2d486190acdc78b7f0a0fc92ba032934032bc0f501b04133e953fa6e26f79bb4bb69c9b6fca9bdca711c9f16493ec67f8072'
|
7
|
+
data.tar.gz: 2cd9def0da8c9fbb63c9fa96233886f6eb656391a39924d8d9210668b8e47335e35bbd072b393a7d1a7d9e4a8640ed9ab3da3061dd3aee1ef0d163844ae0f2f1
|
data/.travis.yml
CHANGED
@@ -2,19 +2,18 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- jruby
|
9
|
-
- rbx-2
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
- 2.7
|
8
|
+
- jruby
|
10
9
|
matrix:
|
11
10
|
allow_failures:
|
12
11
|
- rvm: jruby-9.0.0.0
|
13
|
-
- rvm: rbx-2
|
14
12
|
fast_finish: true
|
15
|
-
script:
|
13
|
+
script: script/ci
|
16
14
|
before_install:
|
17
15
|
- gem update --system
|
16
|
+
- gem update bundler
|
18
17
|
services:
|
19
18
|
- redis-server
|
20
19
|
branches:
|
data/Rakefile
CHANGED
data/lib/lita.rb
CHANGED
@@ -115,6 +115,7 @@ require_relative "lita/timer"
|
|
115
115
|
require_relative "lita/robot"
|
116
116
|
require_relative "lita/adapter"
|
117
117
|
require_relative "lita/adapters/shell"
|
118
|
+
require_relative "lita/adapters/test"
|
118
119
|
require_relative "lita/plugin_builder"
|
119
120
|
require_relative "lita/route_validator"
|
120
121
|
require_relative "lita/handlers/authorization"
|
data/lib/lita/adapter.rb
CHANGED
@@ -4,6 +4,7 @@ module Lita
|
|
4
4
|
# The names of methods that should be implemented by an adapter.
|
5
5
|
# @since 4.4.0
|
6
6
|
REQUIRED_METHODS = %i(
|
7
|
+
chat_service
|
7
8
|
join
|
8
9
|
part
|
9
10
|
roster
|
@@ -46,7 +47,7 @@ module Lita
|
|
46
47
|
# @param hash [Hash] An optional hash of values to be interpolated in the string.
|
47
48
|
# @return [String] The translated string.
|
48
49
|
def translate(key, hash = {})
|
49
|
-
I18n.translate("lita.adapters.#{namespace}.#{key}", hash)
|
50
|
+
I18n.translate("lita.adapters.#{namespace}.#{key}", **hash)
|
50
51
|
end
|
51
52
|
|
52
53
|
alias_method :t, :translate
|
@@ -65,6 +66,12 @@ module Lita
|
|
65
66
|
robot.config.adapters.public_send(self.class.namespace)
|
66
67
|
end
|
67
68
|
|
69
|
+
# @!method chat_service
|
70
|
+
# May return an object exposing chat-service-specific APIs.
|
71
|
+
# @return [Object, nil] The chat service API object, if any.
|
72
|
+
# @abstract This should be implemented by the adapter.
|
73
|
+
# @since 4.6.0
|
74
|
+
|
68
75
|
# @!method join(room_id)
|
69
76
|
# Joins the room with the specified ID.
|
70
77
|
# @param room_id [String] The ID of the room.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Lita
|
2
|
+
# A namespace to hold all subclasses of {Adapter}.
|
3
|
+
module Adapters
|
4
|
+
# An adapter for testing Lita and Lita plugins.
|
5
|
+
# @since 4.6.0
|
6
|
+
class Test < Adapter
|
7
|
+
# Adapter-specific methods exposed through {Robot}.
|
8
|
+
class ChatService
|
9
|
+
def initialize(sent_messages)
|
10
|
+
@sent_messages = sent_messages
|
11
|
+
end
|
12
|
+
|
13
|
+
# An array of recorded outgoing messages.
|
14
|
+
def sent_messages
|
15
|
+
@sent_messages.dup
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(robot)
|
20
|
+
super
|
21
|
+
|
22
|
+
self.sent_messages = []
|
23
|
+
end
|
24
|
+
|
25
|
+
# Adapter-specific methods available via {Robot#chat_service}.
|
26
|
+
def chat_service
|
27
|
+
ChatService.new(sent_messages)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Records outgoing messages.
|
31
|
+
def send_messages(_target, strings)
|
32
|
+
sent_messages.concat(strings)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# An array of recorded outgoing messages.
|
38
|
+
attr_accessor :sent_messages
|
39
|
+
end
|
40
|
+
|
41
|
+
Lita.register_adapter(:test, Test)
|
42
|
+
end
|
43
|
+
end
|
@@ -95,10 +95,8 @@ module Lita
|
|
95
95
|
robot.hooks[:trigger_route].each { |hook| hook.call(response: response, route: route) }
|
96
96
|
handler = new(robot)
|
97
97
|
route.callback.call(handler, response)
|
98
|
-
rescue
|
99
|
-
|
100
|
-
robot.config.robot.error_handler.call(e)
|
101
|
-
raise e if Lita.test_mode?
|
98
|
+
rescue => error
|
99
|
+
log_error(robot, error)
|
102
100
|
end
|
103
101
|
|
104
102
|
private
|
@@ -125,16 +123,6 @@ module Lita
|
|
125
123
|
method: route.callback.method_name || "(block)"
|
126
124
|
)
|
127
125
|
end
|
128
|
-
|
129
|
-
# Logs an error encountered during dispatch.
|
130
|
-
def log_dispatch_error(e)
|
131
|
-
Lita.logger.error I18n.t(
|
132
|
-
"lita.handler.exception",
|
133
|
-
handler: name,
|
134
|
-
message: e.message,
|
135
|
-
backtrace: e.backtrace.join("\n")
|
136
|
-
)
|
137
|
-
end
|
138
126
|
end
|
139
127
|
end
|
140
128
|
end
|
data/lib/lita/handler/common.rb
CHANGED
@@ -33,10 +33,22 @@ module Lita
|
|
33
33
|
# @return [String] The translated string.
|
34
34
|
# @since 3.0.0
|
35
35
|
def translate(key, hash = {})
|
36
|
-
I18n.translate("lita.handlers.#{namespace}.#{key}", hash)
|
36
|
+
I18n.translate("lita.handlers.#{namespace}.#{key}", **hash)
|
37
37
|
end
|
38
38
|
|
39
39
|
alias_method :t, :translate
|
40
|
+
|
41
|
+
# Logs an error raised by a plugin.
|
42
|
+
def log_error(robot, error)
|
43
|
+
robot.config.robot.error_handler.call(error)
|
44
|
+
Lita.logger.error I18n.t(
|
45
|
+
"lita.handler.exception",
|
46
|
+
handler: name,
|
47
|
+
message: error.message,
|
48
|
+
backtrace: error.backtrace.join("\n")
|
49
|
+
)
|
50
|
+
raise error if Lita.test_mode?
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
54
|
# A Redis::Namespace scoped to the handler.
|
@@ -57,7 +57,11 @@ module Lita
|
|
57
57
|
# @return [Boolean] Whether or not the event triggered any callbacks.
|
58
58
|
def trigger(robot, event_name, payload = {})
|
59
59
|
event_subscriptions_for(event_name).map do |callback|
|
60
|
-
|
60
|
+
begin
|
61
|
+
callback.call(new(robot), payload)
|
62
|
+
rescue => error
|
63
|
+
log_error(robot, error)
|
64
|
+
end
|
61
65
|
end.any?
|
62
66
|
end
|
63
67
|
|
data/lib/lita/handlers/info.rb
CHANGED
@@ -40,7 +40,11 @@ module Lita
|
|
40
40
|
|
41
41
|
# A hash of information about Redis.
|
42
42
|
def redis_info
|
43
|
-
@redis_info ||=
|
43
|
+
@redis_info ||= begin
|
44
|
+
r = redis.redis
|
45
|
+
r = r.redis while r.respond_to?(:redis)
|
46
|
+
r.info
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
# The current version of Redis.
|
data/lib/lita/message.rb
CHANGED
@@ -11,6 +11,11 @@ module Lita
|
|
11
11
|
# @return [Lita::Source] The message source.
|
12
12
|
attr_reader :source
|
13
13
|
|
14
|
+
# A hash of arbitrary data that can be populated by Lita adapters and extensions.
|
15
|
+
# @return [Hash] The extension data.
|
16
|
+
# @since 4.7.0
|
17
|
+
attr_reader :extensions
|
18
|
+
|
14
19
|
# @!method user
|
15
20
|
# The user who sent the message.
|
16
21
|
# @return [Lita::User] The user.
|
@@ -34,6 +39,7 @@ module Lita
|
|
34
39
|
@robot = robot
|
35
40
|
@body = body
|
36
41
|
@source = source
|
42
|
+
@extensions = {}
|
37
43
|
|
38
44
|
name_pattern = "@?#{Regexp.escape(@robot.mention_name)}[:,]?\\s+"
|
39
45
|
alias_pattern = "#{Regexp.escape(@robot.alias)}\\s*" if @robot.alias
|
data/lib/lita/robot.rb
CHANGED
@@ -36,13 +36,16 @@ module Lita
|
|
36
36
|
|
37
37
|
def_delegators :registry, :config, :adapters, :handlers, :hooks
|
38
38
|
|
39
|
+
# @!method chat_service
|
40
|
+
# @see Lita::Adapter#chat_service
|
41
|
+
# @since 4.6.0
|
39
42
|
# @!method mention_format(name)
|
40
43
|
# @see Lita::Adapter#mention_format
|
41
44
|
# @since 4.4.0
|
42
45
|
# @!method roster(room)
|
43
46
|
# @see Lita::Adapter#roster
|
44
47
|
# @since 4.4.1
|
45
|
-
def_delegators :adapter, :mention_format, :roster
|
48
|
+
def_delegators :adapter, :chat_service, :mention_format, :roster
|
46
49
|
|
47
50
|
# @param registry [Lita::Registry] The registry for the robot's configuration and plugins.
|
48
51
|
def initialize(registry = Lita)
|
data/lib/lita/rspec/handler.rb
CHANGED
@@ -18,13 +18,27 @@ module Lita
|
|
18
18
|
base.send(:include, Lita::RSpec)
|
19
19
|
|
20
20
|
prepare_handlers(base)
|
21
|
+
prepare_adapter(base)
|
21
22
|
prepare_let_blocks(base)
|
22
23
|
prepare_subject(base)
|
23
|
-
prepare_robot(base)
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
+
# Stub Lita.adapters
|
29
|
+
def prepare_adapter(base)
|
30
|
+
base.class_eval do
|
31
|
+
before do
|
32
|
+
if Lita.version_3_compatibility_mode?
|
33
|
+
Lita.config.robot.adapter = :test
|
34
|
+
else
|
35
|
+
registry.register_adapter(:test, Lita::Adapters::Test)
|
36
|
+
registry.config.robot.adapter = :test
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
# Stub Lita.handlers.
|
29
43
|
def prepare_handlers(base)
|
30
44
|
base.class_eval do
|
@@ -50,20 +64,6 @@ module Lita
|
|
50
64
|
let(:robot) { Robot.new(registry) }
|
51
65
|
let(:source) { Source.new(user: user) }
|
52
66
|
let(:user) { User.create("1", name: "Test User") }
|
53
|
-
let(:replies) { [] }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Stub Lita::Robot#send_messages.
|
58
|
-
def prepare_robot(base)
|
59
|
-
base.class_eval do
|
60
|
-
before do
|
61
|
-
[:send_messages, :send_message].each do |message|
|
62
|
-
allow(robot).to receive(message) do |_target, *strings|
|
63
|
-
replies.concat(strings)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -71,18 +71,27 @@ module Lita
|
|
71
71
|
def prepare_subject(base)
|
72
72
|
base.class_eval do
|
73
73
|
subject { described_class.new(robot) }
|
74
|
-
before { allow(described_class).to receive(:new).and_return(subject) }
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
78
|
+
# An array of strings that have been sent by the robot during the course of a test.
|
79
|
+
# @return [Array<String>] The replies.
|
80
|
+
def replies
|
81
|
+
robot.chat_service.sent_messages
|
82
|
+
end
|
83
|
+
|
79
84
|
# Sends a message to the robot.
|
80
85
|
# @param body [String] The message to send.
|
81
86
|
# @param as [Lita::User] The user sending the message.
|
82
87
|
# @param from [Lita::Room] The room where the message is received from.
|
83
88
|
# @return [void]
|
84
|
-
def send_message(body, as: user, from: nil)
|
85
|
-
message = Message.new(
|
89
|
+
def send_message(body, as: user, from: nil, privately: false)
|
90
|
+
message = Message.new(
|
91
|
+
robot,
|
92
|
+
body,
|
93
|
+
Source.new(user: as, room: from, private_message: privately)
|
94
|
+
)
|
86
95
|
|
87
96
|
robot.receive(message)
|
88
97
|
end
|
@@ -92,8 +101,8 @@ module Lita
|
|
92
101
|
# @param as [Lita::User] The user sending the message.
|
93
102
|
# @param from [Lita::Room] The room where the message is received from.
|
94
103
|
# @return [void]
|
95
|
-
def send_command(body, as: user, from: nil)
|
96
|
-
send_message("#{robot.mention_name}: #{body}", as: as, from: from)
|
104
|
+
def send_command(body, as: user, from: nil, privately: false)
|
105
|
+
send_message("#{robot.mention_name}: #{body}", as: as, from: from, privately: privately)
|
97
106
|
end
|
98
107
|
|
99
108
|
# Returns a Faraday connection hooked up to the currently running robot's Rack app.
|
data/lib/lita/template.rb
CHANGED
data/lib/lita/version.rb
CHANGED
data/lita.gemspec
CHANGED
@@ -18,23 +18,23 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = ">= 2.
|
21
|
+
spec.required_ruby_version = ">= 2.5.0"
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "bundler", ">=
|
24
|
-
spec.add_runtime_dependency "faraday", ">= 0
|
25
|
-
spec.add_runtime_dependency "http_router", ">= 0.11
|
26
|
-
spec.add_runtime_dependency "ice_nine", ">= 0.11
|
27
|
-
spec.add_runtime_dependency "i18n", ">=
|
28
|
-
spec.add_runtime_dependency "multi_json", ">= 1.
|
29
|
-
spec.add_runtime_dependency "puma", ">=
|
30
|
-
spec.add_runtime_dependency "rack", ">=
|
31
|
-
spec.add_runtime_dependency "rb-readline", ">= 0.5
|
32
|
-
spec.add_runtime_dependency "redis-namespace", ">= 1.
|
33
|
-
spec.add_runtime_dependency "thor", ">= 0
|
23
|
+
spec.add_runtime_dependency "bundler", ">= 2.0"
|
24
|
+
spec.add_runtime_dependency "faraday", ">= 1.0"
|
25
|
+
spec.add_runtime_dependency "http_router", ">= 0.11"
|
26
|
+
spec.add_runtime_dependency "ice_nine", ">= 0.11"
|
27
|
+
spec.add_runtime_dependency "i18n", ">= 1.8"
|
28
|
+
spec.add_runtime_dependency "multi_json", ">= 1.15"
|
29
|
+
spec.add_runtime_dependency "puma", ">= 4.3"
|
30
|
+
spec.add_runtime_dependency "rack", ">= 2.2"
|
31
|
+
spec.add_runtime_dependency "rb-readline", ">= 0.5"
|
32
|
+
spec.add_runtime_dependency "redis-namespace", ">= 1.7"
|
33
|
+
spec.add_runtime_dependency "thor", ">= 1.0"
|
34
34
|
|
35
35
|
spec.add_development_dependency "rake"
|
36
36
|
spec.add_development_dependency "rack-test"
|
37
|
-
spec.add_development_dependency "rspec"
|
37
|
+
spec.add_development_dependency "rspec"
|
38
38
|
spec.add_development_dependency "simplecov"
|
39
39
|
spec.add_development_dependency "coveralls"
|
40
40
|
spec.add_development_dependency "pry"
|
data/script/ci
ADDED
@@ -3,6 +3,15 @@ require "spec_helper"
|
|
3
3
|
describe Lita::ConfigurationBuilder do
|
4
4
|
let(:config) { subject.build }
|
5
5
|
|
6
|
+
# For some reason RSpec is no longer capturing tracebacks to
|
7
|
+
# stderr, so we do it manually to avoid cluttering the test output.
|
8
|
+
around do |example|
|
9
|
+
stderr = $stderr
|
10
|
+
$stderr = StringIO.new
|
11
|
+
example.run
|
12
|
+
$stderr = stderr
|
13
|
+
end
|
14
|
+
|
6
15
|
describe ".load_user_config" do
|
7
16
|
it "loads and evals lita_config.rb" do
|
8
17
|
allow(File).to receive(:exist?).and_return(true)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Lita::Handler::EventRouter do
|
4
|
-
let(:robot) {
|
3
|
+
describe Lita::Handler::EventRouter, lita: true do
|
4
|
+
let(:robot) { Lita::Robot.new(registry) }
|
5
5
|
|
6
6
|
subject do
|
7
7
|
Class.new do
|
@@ -27,6 +27,16 @@ describe Lita::Handler::EventRouter do
|
|
27
27
|
|
28
28
|
on(:multiple_callbacks) { robot.send_message("first callback") }
|
29
29
|
on(:multiple_callbacks) { robot.send_message("second callback") }
|
30
|
+
|
31
|
+
on(:multiple_errors) do
|
32
|
+
robot.send_message("first error")
|
33
|
+
raise ArgumentError, "first"
|
34
|
+
end
|
35
|
+
|
36
|
+
on(:multiple_errors) do
|
37
|
+
robot.send_message("second error")
|
38
|
+
raise ArgumentError, "second"
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
@@ -61,5 +71,47 @@ describe Lita::Handler::EventRouter do
|
|
61
71
|
subject.trigger(robot, "connected")
|
62
72
|
subject.trigger(robot, " ConNected ")
|
63
73
|
end
|
74
|
+
|
75
|
+
context "not in test mode" do
|
76
|
+
around do |example|
|
77
|
+
test_mode = Lita.test_mode?
|
78
|
+
Lita.test_mode = false
|
79
|
+
begin
|
80
|
+
example.run
|
81
|
+
ensure
|
82
|
+
Lita.test_mode = test_mode
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "doesn't stop triggering callbacks after an exception is raised" do
|
87
|
+
expect(robot).to receive(:send_message).with("first error").once
|
88
|
+
expect(robot).to receive(:send_message).with("second error").once
|
89
|
+
subject.trigger(robot, :multiple_errors)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "reports callback exceptions to the error handler" do
|
93
|
+
allow(robot).to receive(:send_message)
|
94
|
+
expect(registry.config.robot.error_handler).to receive(:call).twice
|
95
|
+
subject.trigger(robot, :multiple_errors)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "in test mode" do
|
100
|
+
around do |example|
|
101
|
+
test_mode = Lita.test_mode?
|
102
|
+
Lita.test_mode = true
|
103
|
+
begin
|
104
|
+
example.run
|
105
|
+
ensure
|
106
|
+
Lita.test_mode = test_mode
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "re-raises callback exceptions immediately" do
|
111
|
+
allow(robot).to receive(:send_message)
|
112
|
+
expect(registry.config.robot.error_handler).to receive(:call).once
|
113
|
+
expect { subject.trigger(robot, :multiple_errors) }.to raise_error(ArgumentError, "first")
|
114
|
+
end
|
115
|
+
end
|
64
116
|
end
|
65
117
|
end
|
@@ -92,7 +92,7 @@ describe handler, lita_handler: true do
|
|
92
92
|
it "calls the error handler with the exception as argument" do
|
93
93
|
expect(registry.config.robot.error_handler).to receive(:call).with(instance_of(TypeError))
|
94
94
|
|
95
|
-
expect { http.get("/boom") }.to raise_error(TypeError, "String can't be coerced into
|
95
|
+
expect { http.get("/boom") }.to raise_error(TypeError, "String can't be coerced into Integer")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -39,7 +39,7 @@ describe Lita::Handlers::Info, lita_handler: true do
|
|
39
39
|
|
40
40
|
it "includes the adapter being used" do
|
41
41
|
subject.web(request, response)
|
42
|
-
expect(json).to include("adapter" =>
|
42
|
+
expect(json).to include("adapter" => registry.config.robot.adapter.to_s)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "includes the robot's name" do
|
data/spec/lita/message_spec.rb
CHANGED
@@ -21,6 +21,14 @@ describe Lita::Message do
|
|
21
21
|
expect(subject.source).to eq(source)
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "#extensions" do
|
25
|
+
it "can be populated with arbitrary data" do
|
26
|
+
subject.extensions[:foo] = :bar
|
27
|
+
|
28
|
+
expect(subject.extensions[:foo]).to eq(:bar)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
24
32
|
describe "#args" do
|
25
33
|
it "returns an array of the 2nd through nth word in the message" do
|
26
34
|
subject = described_class.new(robot, "args foo bar", source)
|
data/spec/lita/robot_spec.rb
CHANGED
@@ -44,6 +44,10 @@ describe Lita::Robot, lita: true do
|
|
44
44
|
subject.roster(instance_double("Lita::Room"))
|
45
45
|
end
|
46
46
|
|
47
|
+
it "exposes Adapter#chat_service" do
|
48
|
+
expect { subject.chat_service }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
47
51
|
context "with registered handlers" do
|
48
52
|
let(:handler1) { Class.new(Lita::Handler) { namespace :test } }
|
49
53
|
let(:handler2) { Class.new(Lita::Handler) { namespace :test } }
|
@@ -73,6 +77,15 @@ describe Lita::Robot, lita: true do
|
|
73
77
|
describe "#run" do
|
74
78
|
let(:thread) { instance_double("Thread", :abort_on_exception= => true, join: nil) }
|
75
79
|
|
80
|
+
# For some reason RSpec is no longer capturing tracebacks to
|
81
|
+
# stderr, so we do it manually to avoid cluttering the test output.
|
82
|
+
around do |example|
|
83
|
+
stderr = $stderr
|
84
|
+
$stderr = StringIO.new
|
85
|
+
example.run
|
86
|
+
$stderr = stderr
|
87
|
+
end
|
88
|
+
|
76
89
|
before do
|
77
90
|
allow_any_instance_of(Lita::Adapters::Shell).to receive(:run)
|
78
91
|
allow_any_instance_of(Puma::Server).to receive(:run)
|
data/spec/lita/rspec_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
handler_class = Class.new(Lita::Handler) do
|
4
4
|
route(/^message$/, :message)
|
5
5
|
route(/^channel$/, :channel)
|
6
|
+
route(/^private message$/, :private_message)
|
6
7
|
route(/^command$/, :command, command: true)
|
7
8
|
route("restricted", :restricted, restrict_to: :some_group)
|
8
9
|
route("admins only", :admins_only, restrict_to: :admins)
|
@@ -24,6 +25,14 @@ handler_class = Class.new(Lita::Handler) do
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
28
|
+
def private_message(response)
|
29
|
+
if response.private_message?
|
30
|
+
response.reply("Private")
|
31
|
+
else
|
32
|
+
response.reply("Public")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
27
36
|
def command(response)
|
28
37
|
response.reply("a", "command")
|
29
38
|
end
|
@@ -108,6 +117,12 @@ describe handler_class, lita_handler: true do
|
|
108
117
|
send_message("message")
|
109
118
|
expect(replies).to eq(["Test User"])
|
110
119
|
end
|
120
|
+
|
121
|
+
it "does not memoize #replies on first access" do
|
122
|
+
replies
|
123
|
+
send_message("message")
|
124
|
+
expect(replies).to eq(["Test User"])
|
125
|
+
end
|
111
126
|
end
|
112
127
|
|
113
128
|
describe "#channel" do
|
@@ -116,12 +131,40 @@ describe handler_class, lita_handler: true do
|
|
116
131
|
send_message("channel", from: room)
|
117
132
|
expect(replies).to eq(%w(1 Room))
|
118
133
|
end
|
134
|
+
|
119
135
|
it "replies with no channel if not sent from room" do
|
120
136
|
send_message("channel")
|
121
137
|
expect(replies).to eq(["No room"])
|
122
138
|
end
|
123
139
|
end
|
124
140
|
|
141
|
+
describe "#private_message" do
|
142
|
+
let(:another_user) do
|
143
|
+
Lita::User.create(2, name: "Another User")
|
144
|
+
end
|
145
|
+
|
146
|
+
let(:room) do
|
147
|
+
Lita::Room.create_or_update(1, name: "Room")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "replies with Private in response to a private message" do
|
151
|
+
send_message("private message", as: another_user, privately: true)
|
152
|
+
expect(source).to be_a_private_message
|
153
|
+
expect(replies.last).to eq("Private")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "replies with Private in response to a private command" do
|
157
|
+
send_command("private message", as: another_user, privately: true)
|
158
|
+
expect(source).to be_a_private_message
|
159
|
+
expect(replies.last).to eq("Private")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "replies with Public in response to a public message" do
|
163
|
+
send_message("private message", as: another_user, from: room)
|
164
|
+
expect(replies.last).to eq("Public")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
125
168
|
describe "#command" do
|
126
169
|
it "replies with two strings" do
|
127
170
|
send_command("command")
|
data/spec/lita_spec.rb
CHANGED
@@ -84,8 +84,15 @@ describe Lita do
|
|
84
84
|
around do |example|
|
85
85
|
test_mode = Lita.test_mode?
|
86
86
|
Lita.test_mode = false
|
87
|
+
|
88
|
+
stderr = $stderr
|
89
|
+
$stderr = StringIO.new
|
90
|
+
|
87
91
|
example.run
|
92
|
+
|
88
93
|
Lita.test_mode = test_mode
|
94
|
+
|
95
|
+
$stderr = stderr
|
89
96
|
end
|
90
97
|
|
91
98
|
it "logs a fatal warning and raises an exception if it can't connect to Redis" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.8.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Cuadra
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,154 +16,154 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: http_router
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.11
|
47
|
+
version: '0.11'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.11
|
54
|
+
version: '0.11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: ice_nine
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.11
|
61
|
+
version: '0.11'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.11
|
68
|
+
version: '0.11'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: i18n
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '1.8'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '1.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: multi_json
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: '1.15'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
96
|
+
version: '1.15'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: puma
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: '4.3'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: '4.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rack
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: '2.2'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '2.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rb-readline
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.5
|
131
|
+
version: '0.5'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.5
|
138
|
+
version: '0.5'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: redis-namespace
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
145
|
+
version: '1.7'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
152
|
+
version: '1.7'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: thor
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0
|
159
|
+
version: '1.0'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0
|
166
|
+
version: '1.0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,14 +198,14 @@ dependencies:
|
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: '0'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: simplecov
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -282,6 +282,7 @@ files:
|
|
282
282
|
- lib/lita.rb
|
283
283
|
- lib/lita/adapter.rb
|
284
284
|
- lib/lita/adapters/shell.rb
|
285
|
+
- lib/lita/adapters/test.rb
|
285
286
|
- lib/lita/authorization.rb
|
286
287
|
- lib/lita/callback.rb
|
287
288
|
- lib/lita/cli.rb
|
@@ -331,6 +332,7 @@ files:
|
|
331
332
|
- lib/lita/util.rb
|
332
333
|
- lib/lita/version.rb
|
333
334
|
- lita.gemspec
|
335
|
+
- script/ci
|
334
336
|
- spec/lita/adapter_spec.rb
|
335
337
|
- spec/lita/adapters/shell_spec.rb
|
336
338
|
- spec/lita/authorization_spec.rb
|
@@ -389,7 +391,7 @@ homepage: https://github.com/jimmycuadra/lita
|
|
389
391
|
licenses:
|
390
392
|
- MIT
|
391
393
|
metadata: {}
|
392
|
-
post_install_message:
|
394
|
+
post_install_message:
|
393
395
|
rdoc_options: []
|
394
396
|
require_paths:
|
395
397
|
- lib
|
@@ -397,16 +399,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
397
399
|
requirements:
|
398
400
|
- - ">="
|
399
401
|
- !ruby/object:Gem::Version
|
400
|
-
version: 2.
|
402
|
+
version: 2.5.0
|
401
403
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
402
404
|
requirements:
|
403
|
-
- - "
|
405
|
+
- - ">"
|
404
406
|
- !ruby/object:Gem::Version
|
405
|
-
version:
|
407
|
+
version: 1.3.1
|
406
408
|
requirements: []
|
407
|
-
|
408
|
-
|
409
|
-
signing_key:
|
409
|
+
rubygems_version: 3.1.2
|
410
|
+
signing_key:
|
410
411
|
specification_version: 4
|
411
412
|
summary: ChatOps framework for Ruby. Lita is a robot companion for your chat room.
|
412
413
|
test_files:
|