lita 3.3.1 → 4.0.0.rc1
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/.rubocop.yml +1 -1
- data/.travis.yml +3 -0
- data/lib/lita.rb +45 -97
- data/lib/lita/adapter.rb +38 -17
- data/lib/lita/adapters/shell.rb +5 -3
- data/lib/lita/authorization.rb +109 -60
- data/lib/lita/builder.rb +38 -0
- data/lib/lita/callback.rb +37 -0
- data/lib/lita/cli.rb +2 -0
- data/lib/lita/config.rb +1 -18
- data/lib/lita/configurable.rb +29 -0
- data/lib/lita/configuration.rb +179 -0
- data/lib/lita/configuration_validator.rb +66 -0
- data/lib/lita/daemon.rb +4 -11
- data/lib/lita/default_configuration.rb +146 -0
- data/lib/lita/errors.rb +9 -0
- data/lib/lita/handler.rb +5 -264
- data/lib/lita/handler/chat_router.rb +130 -0
- data/lib/lita/handler/common.rb +114 -0
- data/lib/lita/handler/event_router.rb +77 -0
- data/lib/lita/handler/http_router.rb +26 -0
- data/lib/lita/handlers/authorization.rb +13 -18
- data/lib/lita/handlers/deprecation_check.rb +24 -0
- data/lib/lita/handlers/help.rb +5 -3
- data/lib/lita/handlers/info.rb +2 -2
- data/lib/lita/http_callback.rb +29 -0
- data/lib/lita/http_route.rb +41 -26
- data/lib/lita/namespace.rb +23 -0
- data/lib/lita/rack_app.rb +29 -2
- data/lib/lita/registry.rb +133 -0
- data/lib/lita/robot.rb +58 -20
- data/lib/lita/route_validator.rb +12 -4
- data/lib/lita/rspec.rb +23 -14
- data/lib/lita/rspec/handler.rb +93 -23
- data/lib/lita/rspec/matchers/chat_route_matcher.rb +48 -0
- data/lib/lita/rspec/matchers/deprecated.rb +36 -0
- data/lib/lita/rspec/matchers/event_route_matcher.rb +27 -0
- data/lib/lita/rspec/matchers/http_route_matcher.rb +18 -60
- data/lib/lita/user.rb +0 -6
- data/lib/lita/util.rb +1 -8
- data/lib/lita/version.rb +1 -1
- data/lita.gemspec +1 -0
- data/spec/lita/adapter_spec.rb +25 -7
- data/spec/lita/adapters/shell_spec.rb +24 -4
- data/spec/lita/authorization_spec.rb +57 -38
- data/spec/lita/builder_spec.rb +39 -0
- data/spec/lita/config_spec.rb +0 -24
- data/spec/lita/configuration_spec.rb +222 -0
- data/spec/lita/configuration_validator_spec.rb +112 -0
- data/spec/lita/daemon_spec.rb +2 -2
- data/spec/lita/default_configuration_spec.rb +254 -0
- data/spec/lita/handler/chat_router_spec.rb +192 -0
- data/spec/lita/handler/common_spec.rb +272 -0
- data/spec/lita/handler/event_router_spec.rb +54 -0
- data/spec/lita/handler/http_router_spec.rb +106 -0
- data/spec/lita/handler_spec.rb +20 -291
- data/spec/lita/handlers/authorization_spec.rb +9 -11
- data/spec/lita/handlers/deprecation_check_spec.rb +21 -0
- data/spec/lita/handlers/help_spec.rb +31 -9
- data/spec/lita/handlers/info_spec.rb +2 -2
- data/spec/lita/handlers/room_spec.rb +5 -3
- data/spec/lita/robot_spec.rb +30 -11
- data/spec/lita/rspec_spec.rb +71 -31
- data/spec/lita/user_spec.rb +2 -2
- data/spec/lita_spec.rb +62 -4
- data/spec/spec_helper.rb +7 -0
- data/templates/locales/en.yml +56 -4
- data/templates/plugin/gemspec.tt +1 -0
- data/templates/plugin/spec/spec_helper.tt +4 -0
- metadata +54 -8
- data/lib/lita/rspec/matchers/event_subscription_matcher.rb +0 -67
- data/lib/lita/rspec/matchers/route_matcher.rb +0 -69
- data/spec/lita/rack_app_spec.rb +0 -92
data/spec/spec_helper.rb
CHANGED
@@ -11,9 +11,16 @@ require "lita"
|
|
11
11
|
require "lita/cli"
|
12
12
|
require "lita/rspec"
|
13
13
|
|
14
|
+
Lita.version_3_compatibility_mode = false
|
15
|
+
|
14
16
|
RSpec.configure do |config|
|
15
17
|
config.mock_with :rspec do |mocks_config|
|
16
18
|
mocks_config.verify_doubled_constant_names = true
|
17
19
|
mocks_config.verify_partial_doubles = true
|
18
20
|
end
|
21
|
+
|
22
|
+
config.before do
|
23
|
+
logger = double("Lita:Logger").as_null_object
|
24
|
+
allow(Lita).to receive(:logger).and_return(logger)
|
25
|
+
end
|
19
26
|
end
|
data/templates/locales/en.yml
CHANGED
@@ -3,6 +3,15 @@ en:
|
|
3
3
|
adapters:
|
4
4
|
shell:
|
5
5
|
startup_message: Type "exit" or "quit" to end the session.
|
6
|
+
auth:
|
7
|
+
class_method_deprecated: >-
|
8
|
+
Lita::Authorization.%{method} will be removed in Lita 5.0. Use the version accessed via
|
9
|
+
Lita::Robot#auth instead.
|
10
|
+
core:
|
11
|
+
register_adapter:
|
12
|
+
block_or_class_required: Lita.register_adapter requires a class in its two argument form.
|
13
|
+
register_handler:
|
14
|
+
block_or_class_required: Lita.register_handler requires a class in its single argument form.
|
6
15
|
handlers:
|
7
16
|
authorization:
|
8
17
|
help:
|
@@ -38,9 +47,14 @@ en:
|
|
38
47
|
part_key: part ROOM_ID
|
39
48
|
part_value: Makes the robot part from the room with room ID ROOM_ID.
|
40
49
|
adapter:
|
41
|
-
name_required: Adapters that are anonymous classes must define self.name.
|
42
50
|
method_not_implemented: "This adapter has not implemented #%{method}."
|
43
51
|
missing_configs: "The following keys are required on config.adapter: %{configs}"
|
52
|
+
require_config_deprecated: >-
|
53
|
+
Lita::Adapter.require_config is deprecated and will be removed in Lita 5.0.
|
54
|
+
Use Lita::Adapter.config instead.
|
55
|
+
required_configs_deprecated: >-
|
56
|
+
Lita::Adapter.required_configs is deprecated and will be removed in Lita 5.0.
|
57
|
+
Use Lita::Adapter.configuration instead.
|
44
58
|
cli:
|
45
59
|
no_gemfile_warning: >-
|
46
60
|
The default command "start" must be run inside a Lita project. Try running `lita new` to
|
@@ -48,30 +62,68 @@ en:
|
|
48
62
|
travis_question: Do you want to test your plugin on Travis CI?
|
49
63
|
coveralls_question: |-
|
50
64
|
Do you want to generate code coverage information with SimpleCov and Coveralls.io?
|
65
|
+
daemon_deprecated: >-
|
66
|
+
Lita's built-in daemonization is deprecated without replacement and will be removed in
|
67
|
+
Lita 5.0. Use your operating system's process manager instead.
|
51
68
|
config:
|
69
|
+
adapter_deprecated:
|
70
|
+
config.adapter is deprecated and will be removed in Lita 5.0. Use config.adapters instead.
|
52
71
|
exception: |
|
53
72
|
Lita configuration file could not be processed. The exception was:
|
54
73
|
%{message}
|
55
74
|
Full backtrace:
|
56
75
|
%{backtrace}
|
76
|
+
handler_default_config_deprecated: >-
|
77
|
+
Lita::Handler.default_config is deprecated and will be removed in Lita 5.0.
|
78
|
+
Use Lita::Handler.config instead. The method was found defined in the %{name} handler.
|
79
|
+
redis_struct_access_deprecated: >-
|
80
|
+
Struct-style access of config.redis is deprecated and will be removed in Lita 5.0.
|
81
|
+
config.redis is now a hash.
|
82
|
+
missing_required_adapter_attribute: >-
|
83
|
+
Configuration attribute "%{attribute}" is required for "%{adapter}" adapter.
|
84
|
+
missing_required_handler_attribute: >-
|
85
|
+
Configuration attribute "%{attribute}" is required for "%{handler}" handler.
|
57
86
|
daemon:
|
58
87
|
pid_exists: >-
|
59
88
|
PID file exists at %{path}. Lita may already be running. Kill the existing process or
|
60
89
|
remove the PID file and then start Lita.
|
61
90
|
kill_failure: "Failed to kill existing Lita process %{pid}."
|
62
91
|
handler:
|
63
|
-
name_required: Handlers that are anonymous classes must define self.name.
|
64
92
|
dispatch: "Dispatching message to %{handler}#%{method}."
|
65
93
|
exception: |
|
66
94
|
%{handler} crashed. The exception was:
|
67
95
|
%{message}
|
68
96
|
Full backtrace:
|
69
97
|
%{backtrace}
|
98
|
+
http:
|
99
|
+
exception: |
|
100
|
+
Lita's built-in web server could not be started. The exception was:
|
101
|
+
%{message}
|
102
|
+
Full backtrace:
|
103
|
+
%{backtrace}
|
104
|
+
plugin:
|
105
|
+
name_required: Plugins that are anonymous classes must set a namespace or define self.name.
|
106
|
+
redis:
|
107
|
+
exception: |
|
108
|
+
Lita could not connect to Redis. The exception was:
|
109
|
+
%{message}
|
110
|
+
Full backtrace:
|
111
|
+
%{backtrace}
|
70
112
|
robot:
|
71
113
|
unknown_adapter: "Unknown adapter: :%{adapter}."
|
72
114
|
rspec:
|
73
115
|
full_suite_required: Lita::RSpec requires both RSpec::Mocks and RSpec::Expectations.
|
74
116
|
version_3_required: RSpec::Core 3 or greater is required to use Lita::RSpec.
|
117
|
+
rack_test_required: Rack::Test is required to use the `http` method of Lita::RSpec.
|
118
|
+
lita_3_compatibility_mode: >-
|
119
|
+
WARNING: Lita 3 compatibility mode is currently enabled. It is recommended that you disable
|
120
|
+
it by adding the following code to spec/spec_helper.rb:
|
121
|
+
|
122
|
+
require "lita/rspec"
|
123
|
+
Lita.version_3_compatibility_mode = false
|
124
|
+
|
125
|
+
This will ensure that your test suite works with all the changes introduced in Lita 4. The
|
126
|
+
compatibility mode will be removed in Lita 5.
|
75
127
|
route_failure: |-
|
76
128
|
Expected message "%{message}" to route to :%{route}, but didn't.
|
77
129
|
negative_route_failure: |-
|
@@ -84,7 +136,7 @@ en:
|
|
84
136
|
Expected triggering event "%{event}" to invoke :%{route}, but didn't.
|
85
137
|
negative_event_subscription_failure: |-
|
86
138
|
Expected triggering event "%{event}" not to invoke :%{route}, but did.
|
139
|
+
matcher_deprecated: >-
|
140
|
+
`%{old_method}` is deprecated and will be removed in Lita 5.0. Use `%{new_method}` instead.
|
87
141
|
source:
|
88
142
|
user_or_room_required: Either a user or a room is required.
|
89
|
-
user:
|
90
|
-
find_deprecated: Lita::User.find will be removed in Lita 4.0. Use Lita::User.create instead.
|
data/templates/plugin/gemspec.tt
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rack-test"
|
21
22
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
22
23
|
<%- if config[:coveralls] -%>
|
23
24
|
spec.add_development_dependency "simplecov"
|
@@ -10,3 +10,7 @@ SimpleCov.start { add_filter "/spec/" }
|
|
10
10
|
<%- end -%>
|
11
11
|
require "<%= config[:gem_name] %>"
|
12
12
|
require "lita/rspec"
|
13
|
+
|
14
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
15
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
16
|
+
Lita.version_3_compatibility_mode = false
|
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
|
+
version: 4.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Cuadra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rack-test
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: rspec
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -269,27 +283,43 @@ files:
|
|
269
283
|
- lib/lita/adapter.rb
|
270
284
|
- lib/lita/adapters/shell.rb
|
271
285
|
- lib/lita/authorization.rb
|
286
|
+
- lib/lita/builder.rb
|
287
|
+
- lib/lita/callback.rb
|
272
288
|
- lib/lita/cli.rb
|
273
289
|
- lib/lita/common.rb
|
274
290
|
- lib/lita/config.rb
|
291
|
+
- lib/lita/configurable.rb
|
292
|
+
- lib/lita/configuration.rb
|
293
|
+
- lib/lita/configuration_validator.rb
|
275
294
|
- lib/lita/daemon.rb
|
295
|
+
- lib/lita/default_configuration.rb
|
296
|
+
- lib/lita/errors.rb
|
276
297
|
- lib/lita/handler.rb
|
298
|
+
- lib/lita/handler/chat_router.rb
|
299
|
+
- lib/lita/handler/common.rb
|
300
|
+
- lib/lita/handler/event_router.rb
|
301
|
+
- lib/lita/handler/http_router.rb
|
277
302
|
- lib/lita/handlers/authorization.rb
|
303
|
+
- lib/lita/handlers/deprecation_check.rb
|
278
304
|
- lib/lita/handlers/help.rb
|
279
305
|
- lib/lita/handlers/info.rb
|
280
306
|
- lib/lita/handlers/room.rb
|
307
|
+
- lib/lita/http_callback.rb
|
281
308
|
- lib/lita/http_route.rb
|
282
309
|
- lib/lita/logger.rb
|
283
310
|
- lib/lita/message.rb
|
311
|
+
- lib/lita/namespace.rb
|
284
312
|
- lib/lita/rack_app.rb
|
313
|
+
- lib/lita/registry.rb
|
285
314
|
- lib/lita/response.rb
|
286
315
|
- lib/lita/robot.rb
|
287
316
|
- lib/lita/route_validator.rb
|
288
317
|
- lib/lita/rspec.rb
|
289
318
|
- lib/lita/rspec/handler.rb
|
290
|
-
- lib/lita/rspec/matchers/
|
319
|
+
- lib/lita/rspec/matchers/chat_route_matcher.rb
|
320
|
+
- lib/lita/rspec/matchers/deprecated.rb
|
321
|
+
- lib/lita/rspec/matchers/event_route_matcher.rb
|
291
322
|
- lib/lita/rspec/matchers/http_route_matcher.rb
|
292
|
-
- lib/lita/rspec/matchers/route_matcher.rb
|
293
323
|
- lib/lita/source.rb
|
294
324
|
- lib/lita/timer.rb
|
295
325
|
- lib/lita/user.rb
|
@@ -299,16 +329,24 @@ files:
|
|
299
329
|
- spec/lita/adapter_spec.rb
|
300
330
|
- spec/lita/adapters/shell_spec.rb
|
301
331
|
- spec/lita/authorization_spec.rb
|
332
|
+
- spec/lita/builder_spec.rb
|
302
333
|
- spec/lita/config_spec.rb
|
334
|
+
- spec/lita/configuration_spec.rb
|
335
|
+
- spec/lita/configuration_validator_spec.rb
|
303
336
|
- spec/lita/daemon_spec.rb
|
337
|
+
- spec/lita/default_configuration_spec.rb
|
338
|
+
- spec/lita/handler/chat_router_spec.rb
|
339
|
+
- spec/lita/handler/common_spec.rb
|
340
|
+
- spec/lita/handler/event_router_spec.rb
|
341
|
+
- spec/lita/handler/http_router_spec.rb
|
304
342
|
- spec/lita/handler_spec.rb
|
305
343
|
- spec/lita/handlers/authorization_spec.rb
|
344
|
+
- spec/lita/handlers/deprecation_check_spec.rb
|
306
345
|
- spec/lita/handlers/help_spec.rb
|
307
346
|
- spec/lita/handlers/info_spec.rb
|
308
347
|
- spec/lita/handlers/room_spec.rb
|
309
348
|
- spec/lita/logger_spec.rb
|
310
349
|
- spec/lita/message_spec.rb
|
311
|
-
- spec/lita/rack_app_spec.rb
|
312
350
|
- spec/lita/response_spec.rb
|
313
351
|
- spec/lita/robot_spec.rb
|
314
352
|
- spec/lita/rspec_spec.rb
|
@@ -348,9 +386,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
348
386
|
version: 2.0.0
|
349
387
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
350
388
|
requirements:
|
351
|
-
- - "
|
389
|
+
- - ">"
|
352
390
|
- !ruby/object:Gem::Version
|
353
|
-
version:
|
391
|
+
version: 1.3.1
|
354
392
|
requirements: []
|
355
393
|
rubyforge_project:
|
356
394
|
rubygems_version: 2.2.2
|
@@ -361,16 +399,24 @@ test_files:
|
|
361
399
|
- spec/lita/adapter_spec.rb
|
362
400
|
- spec/lita/adapters/shell_spec.rb
|
363
401
|
- spec/lita/authorization_spec.rb
|
402
|
+
- spec/lita/builder_spec.rb
|
364
403
|
- spec/lita/config_spec.rb
|
404
|
+
- spec/lita/configuration_spec.rb
|
405
|
+
- spec/lita/configuration_validator_spec.rb
|
365
406
|
- spec/lita/daemon_spec.rb
|
407
|
+
- spec/lita/default_configuration_spec.rb
|
408
|
+
- spec/lita/handler/chat_router_spec.rb
|
409
|
+
- spec/lita/handler/common_spec.rb
|
410
|
+
- spec/lita/handler/event_router_spec.rb
|
411
|
+
- spec/lita/handler/http_router_spec.rb
|
366
412
|
- spec/lita/handler_spec.rb
|
367
413
|
- spec/lita/handlers/authorization_spec.rb
|
414
|
+
- spec/lita/handlers/deprecation_check_spec.rb
|
368
415
|
- spec/lita/handlers/help_spec.rb
|
369
416
|
- spec/lita/handlers/info_spec.rb
|
370
417
|
- spec/lita/handlers/room_spec.rb
|
371
418
|
- spec/lita/logger_spec.rb
|
372
419
|
- spec/lita/message_spec.rb
|
373
|
-
- spec/lita/rack_app_spec.rb
|
374
420
|
- spec/lita/response_spec.rb
|
375
421
|
- spec/lita/robot_spec.rb
|
376
422
|
- spec/lita/rspec_spec.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module Lita
|
2
|
-
module RSpec
|
3
|
-
# A namespace to hold all of Lita's RSpec matchers.
|
4
|
-
module Matchers
|
5
|
-
# Used to complete an event subscription test chain.
|
6
|
-
class EventSubscriptionMatcher
|
7
|
-
attr_accessor :context, :event_name, :expectation
|
8
|
-
attr_reader :expected_route
|
9
|
-
|
10
|
-
def initialize(context, event_name, expectation: true)
|
11
|
-
self.context = context
|
12
|
-
self.event_name = event_name
|
13
|
-
self.expectation = expectation
|
14
|
-
end
|
15
|
-
|
16
|
-
# Sets an expectation that a handler method will or will not be called in
|
17
|
-
# response to a triggered event, then triggers the event.
|
18
|
-
# @param target_method_name [String, Symbol] The name of the method that
|
19
|
-
# should or should not be triggered.
|
20
|
-
# @return [void]
|
21
|
-
def to(target_method_name)
|
22
|
-
self.expected_route = target_method_name
|
23
|
-
|
24
|
-
e = expectation
|
25
|
-
ev = event_name
|
26
|
-
i = i18n_key
|
27
|
-
|
28
|
-
context.instance_eval do
|
29
|
-
called = false
|
30
|
-
allow(subject).to receive(target_method_name) { called = true }
|
31
|
-
robot.trigger(ev)
|
32
|
-
expect(called).to be(e), I18n.t(i, event: ev, route: target_method_name)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def description_prefix
|
39
|
-
if expectation
|
40
|
-
"routes event"
|
41
|
-
else
|
42
|
-
"doesn't route event"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def expected_route=(route)
|
47
|
-
@expected_route = route
|
48
|
-
set_description
|
49
|
-
end
|
50
|
-
|
51
|
-
def i18n_key
|
52
|
-
if expectation
|
53
|
-
"lita.rspec.event_subscription_failure"
|
54
|
-
else
|
55
|
-
"lita.rspec.negative_event_subscription_failure"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def set_description
|
60
|
-
description = %(#{description_prefix} "#{event_name}")
|
61
|
-
description << " to :#{expected_route}" if expected_route
|
62
|
-
::RSpec.current_example.metadata[:description] = description
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Lita
|
2
|
-
module RSpec
|
3
|
-
# A namespace to hold all of Lita's RSpec matchers.
|
4
|
-
module Matchers
|
5
|
-
# Used to complete a chat routing test chain.
|
6
|
-
class RouteMatcher
|
7
|
-
attr_accessor :context, :expectation, :message_body
|
8
|
-
attr_reader :expected_route
|
9
|
-
|
10
|
-
def initialize(context, message_body, expectation: true)
|
11
|
-
self.context = context
|
12
|
-
self.message_body = message_body
|
13
|
-
self.expectation = expectation
|
14
|
-
set_description
|
15
|
-
end
|
16
|
-
|
17
|
-
# Sets an expectation that a route will or will not be triggered, then
|
18
|
-
# sends the message originally provided.
|
19
|
-
# @param route [Symbol] The name of the method that should or should not
|
20
|
-
# be triggered.
|
21
|
-
# @return [void]
|
22
|
-
def to(route)
|
23
|
-
self.expected_route = route
|
24
|
-
|
25
|
-
e = expectation
|
26
|
-
b = message_body
|
27
|
-
i = i18n_key
|
28
|
-
|
29
|
-
context.instance_eval do
|
30
|
-
allow(Authorization).to receive(:user_in_group?).and_return(true)
|
31
|
-
called = false
|
32
|
-
allow(subject).to receive(route) { called = true }
|
33
|
-
send_message(b)
|
34
|
-
expect(called).to be(e), I18n.t(i, message: b, route: route)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def description_prefix
|
41
|
-
if expectation
|
42
|
-
"routes"
|
43
|
-
else
|
44
|
-
"doesn't route"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def expected_route=(route)
|
49
|
-
@expected_route = route
|
50
|
-
set_description
|
51
|
-
end
|
52
|
-
|
53
|
-
def i18n_key
|
54
|
-
if expectation
|
55
|
-
"lita.rspec.route_failure"
|
56
|
-
else
|
57
|
-
"lita.rspec.negative_route_failure"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def set_description
|
62
|
-
description = %(#{description_prefix} "#{message_body}")
|
63
|
-
description << " to :#{expected_route}" if expected_route
|
64
|
-
::RSpec.current_example.metadata[:description] = description
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/lita/rack_app_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Lita::RackApp do
|
4
|
-
let(:handler_class) do
|
5
|
-
Class.new(Lita::Handler) do
|
6
|
-
http.get "web", :web
|
7
|
-
http.post "path/with/:id", :variable
|
8
|
-
http.link "foo", :foo
|
9
|
-
http.get "heres/*a/glob/in/a/path", :glob
|
10
|
-
http.get ":var/otherwise/identical/path", :constraint, var: /\d+/
|
11
|
-
http.get ":var/otherwise/identical/path", :no_constraint
|
12
|
-
|
13
|
-
def web(_request, response)
|
14
|
-
response.write("it worked")
|
15
|
-
end
|
16
|
-
|
17
|
-
def variable(request, response)
|
18
|
-
id = request.env["router.params"][:id]
|
19
|
-
response.write("id is #{id}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def glob(request, response)
|
23
|
-
segments = request.env["router.params"][:a]
|
24
|
-
response.write(segments.join("/"))
|
25
|
-
end
|
26
|
-
|
27
|
-
def constraint(_request, response)
|
28
|
-
response.write("constraint")
|
29
|
-
end
|
30
|
-
|
31
|
-
def no_constraint(_request, response)
|
32
|
-
response.write("no constraint")
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.name
|
36
|
-
"Lita::Handlers::Test"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:robot) { instance_double("Lita::Robot") }
|
42
|
-
|
43
|
-
before { allow(Lita).to receive(:handlers).and_return([handler_class]) }
|
44
|
-
|
45
|
-
subject { described_class.new(robot) }
|
46
|
-
|
47
|
-
it "responds to requests for simple paths" do
|
48
|
-
env = Rack::MockRequest.env_for("/web")
|
49
|
-
status, _headers, body_proxy = subject.call(env)
|
50
|
-
expect(status).to eq(200)
|
51
|
-
expect(body_proxy.body.first).to eq("it worked")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "responds to requests with variable paths" do
|
55
|
-
env = Rack::MockRequest.env_for("/path/with/some_id", method: "POST")
|
56
|
-
status, _headers, body_proxy = subject.call(env)
|
57
|
-
expect(status).to eq(200)
|
58
|
-
expect(body_proxy.body.first).to eq("id is some_id")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "responds to requests with globs in their paths" do
|
62
|
-
env = Rack::MockRequest.env_for("/heres/a/giant/glob/in/a/path")
|
63
|
-
status, _headers, body_proxy = subject.call(env)
|
64
|
-
expect(status).to eq(200)
|
65
|
-
expect(body_proxy.body.first).to eq("a/giant")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "responds to requests with variable path constraints" do
|
69
|
-
env = Rack::MockRequest.env_for("/123/otherwise/identical/path")
|
70
|
-
status, _headers, body_proxy = subject.call(env)
|
71
|
-
expect(status).to eq(200)
|
72
|
-
expect(body_proxy.body.first).to eq("constraint")
|
73
|
-
|
74
|
-
env = Rack::MockRequest.env_for("/an/otherwise/identical/path")
|
75
|
-
status, _headers, body_proxy = subject.call(env)
|
76
|
-
expect(status).to eq(200)
|
77
|
-
expect(body_proxy.body.first).to eq("no constraint")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "responds to HEAD requests for GET routes" do
|
81
|
-
env = Rack::MockRequest.env_for("/web", method: "HEAD")
|
82
|
-
status, _headers, body = subject.call(env)
|
83
|
-
expect(status).to eq(204)
|
84
|
-
expect(body).to be_empty
|
85
|
-
end
|
86
|
-
|
87
|
-
it "doesn't respond to HEAD requests for non-GET routes" do
|
88
|
-
env = Rack::MockRequest.env_for("/path/with/some_id", method: "HEAD")
|
89
|
-
status, _headers, _body = subject.call(env)
|
90
|
-
expect(status).to eq(405)
|
91
|
-
end
|
92
|
-
end
|