lita 4.2.1 → 4.3.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: 84bc810d10e1bb7f969577c1670a4c9c72e0ffbb
4
- data.tar.gz: 81b164c6c02ad46b14002c2ac9beac67755802f0
3
+ metadata.gz: 82c5e0d68ab472c4415df6cad75ebdf1fe52fd56
4
+ data.tar.gz: 7d7ff0871dbc15991a0edb9cf1526a4c49d53366
5
5
  SHA512:
6
- metadata.gz: dfff3d4d0fd43f3efb59ce330c7d7f06e1220f873b46ca3e0e2b15b2eb038aa8737bcd0b036c05094fbab2849cef40236883c703ee8d0e54b8c0f3b242e79b72
7
- data.tar.gz: 86802672a9ee263a436dfc4a3f75dcacf14a6fb7e635999cb7ef62d1d12dac7d7623a36e643c3a5941471ff23525c6cc6da8bf065fc2f2436f3647082ca6c7fe
6
+ metadata.gz: 6326e3526c0a63f9cba4a8b0fadbed2312a3c29321e3833e1b4ddaedd10ee7dbfa5cc060c4c115ca3c8251b150aa0fb5bad8ea9174376429c23281ec710d8632
7
+ data.tar.gz: 21f439582fe5b648ba954924ee9743b29a7a50f457507a7f5966f586eca96f9845d608f584a57d7c4f3d54d0fbfcdd535c235a89192183a479143595cdd3b8e7
@@ -75,6 +75,7 @@ module Lita
75
75
  ConfigurationBuilder.load_user_config(config_path)
76
76
  ConfigurationBuilder.freeze_config(config)
77
77
  ConfigurationValidator.new(self).call
78
+ hooks[:config_finalized].each { |hook| hook.call(config_path: config_path) }
78
79
  self.locale = config.robot.locale
79
80
  Robot.new.run
80
81
  end
@@ -90,8 +90,9 @@ module Lita
90
90
  # @param name [String] The name for the new adapter.
91
91
  # @return [void]
92
92
  def adapter(name)
93
- generate_templates(generate_config(name, "adapter"))
94
- license_message
93
+ config = generate_config(name, "adapter")
94
+ generate_templates(config)
95
+ post_messages(config)
95
96
  end
96
97
 
97
98
  desc "handler NAME", "Generates a new Lita handler"
@@ -99,8 +100,9 @@ module Lita
99
100
  # @param name [String] The name for the new handler.
100
101
  # @return [void]
101
102
  def handler(name)
102
- generate_templates(generate_config(name, "handler"))
103
- license_message
103
+ config = generate_config(name, "handler")
104
+ generate_templates(config)
105
+ post_messages(config)
104
106
  end
105
107
 
106
108
  desc "extension NAME", "Generates a new Lita extension"
@@ -108,8 +110,9 @@ module Lita
108
110
  # @param name [String] The name for the new extension.
109
111
  # @return [void]
110
112
  def extension(name)
111
- generate_templates(generate_config(name, "extension"))
112
- license_message
113
+ config = generate_config(name, "extension")
114
+ generate_templates(config)
115
+ post_messages(config)
113
116
  end
114
117
 
115
118
  desc "version", "Outputs the current version of Lita"
@@ -122,6 +125,10 @@ module Lita
122
125
 
123
126
  private
124
127
 
128
+ def badges_message
129
+ say I18n.t("lita.cli.badges_reminder"), :yellow
130
+ end
131
+
125
132
  def generate_config(name, plugin_type)
126
133
  name, gem_name = normalize_names(name)
127
134
  constant_name = name.split(/_/).map(&:capitalize).join
@@ -198,10 +205,24 @@ module Lita
198
205
  end
199
206
 
200
207
  def optional_content
208
+ travis = yes?(I18n.t("lita.cli.travis_question"))
209
+ coveralls = yes?(I18n.t("lita.cli.coveralls_question"))
210
+ if travis || coveralls
211
+ say I18n.t("lita.cli.badges_message")
212
+ badges = yes?(I18n.t("lita.cli.badges_question"))
213
+ github_user = ask(I18n.t("lita.cli.github_user_question")) if badges
214
+ end
201
215
  {
202
- travis: yes?(I18n.t("lita.cli.travis_question")),
203
- coveralls: yes?(I18n.t("lita.cli.coveralls_question"))
216
+ travis: travis,
217
+ coveralls: coveralls,
218
+ badges: badges,
219
+ github_user: github_user
204
220
  }
205
221
  end
222
+
223
+ def post_messages(config)
224
+ license_message
225
+ badges_message if config[:badges]
226
+ end
206
227
  end
207
228
  end
@@ -139,6 +139,11 @@ module Lita
139
139
  end
140
140
  end
141
141
  config :admins
142
+ config :error_handler, default: -> (_error) {} do
143
+ validate do |value|
144
+ "must respond to #call" unless value.respond_to?(:call)
145
+ end
146
+ end
142
147
  end
143
148
  end
144
149
  end
@@ -88,6 +88,7 @@ module Lita
88
88
  route.callback.call(handler, response)
89
89
  rescue Exception => e
90
90
  log_dispatch_error(e)
91
+ robot.config.robot.error_handler.call(e)
91
92
  raise e if Lita.test_mode?
92
93
  end
93
94
 
@@ -18,9 +18,14 @@ module Lita
18
18
  if request.head?
19
19
  response.status = 204
20
20
  else
21
- handler = @handler_class.new(env["lita.robot"])
21
+ begin
22
+ handler = @handler_class.new(env["lita.robot"])
22
23
 
23
- @callback.call(handler, request, response)
24
+ @callback.call(handler, request, response)
25
+ rescue Exception => e
26
+ env["lita.robot"].config.robot.error_handler.call(e)
27
+ raise
28
+ end
24
29
  end
25
30
 
26
31
  response.finish
@@ -28,10 +28,16 @@ module Lita
28
28
  def prepare_handlers(base)
29
29
  base.class_eval do
30
30
  before do
31
+ handlers = Set.new(
32
+ [described_class] + Array(base.metadata[:additional_lita_handlers])
33
+ )
34
+
31
35
  if Lita.version_3_compatibility_mode?
32
- allow(Lita).to receive(:handlers).and_return(Set.new([described_class]))
36
+ allow(Lita).to receive(:handlers).and_return(handlers)
33
37
  else
34
- registry.register_handler(described_class)
38
+ handlers.each do |handler|
39
+ registry.register_handler(handler)
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "4.2.1"
3
+ VERSION = "4.3.0"
4
4
  end
@@ -157,6 +157,8 @@ handler = Class.new do
157
157
  "Test"
158
158
  end
159
159
 
160
+ route(/boom/) { |_response| 1 + "2" }
161
+
160
162
  route(/one/) { |response| response.reply "got one" }
161
163
  route(/two/) { |response| response.reply "got two" }
162
164
 
@@ -189,4 +191,12 @@ describe handler, lita_handler: true do
189
191
  expect(replies.last).to eq("got three")
190
192
  end
191
193
  end
194
+
195
+ context "when the handler raises an exception" do
196
+ it "calls the error handler with the exception as argument" do
197
+ expect(registry.config.robot.error_handler).to receive(:call).with(instance_of(TypeError))
198
+
199
+ expect { send_message("boom!") }.to raise_error(TypeError)
200
+ end
201
+ end
192
202
  end
@@ -13,6 +13,7 @@ handler = Class.new do
13
13
  http.get ":var/otherwise/identical/path", :no_constraint
14
14
  http.get("block") { |_request, response| response.write("block") }
15
15
  http.get "middleware", :middleware
16
+ http.get "boom", :boom
16
17
 
17
18
  def web(_request, response)
18
19
  response.write("it worked")
@@ -40,6 +41,10 @@ handler = Class.new do
40
41
  response["Custom-Header"] = request.env["header_value"] if request.env["use_header"]
41
42
  response.write("middleware worked") if request.env["custom_rack_middleware_working"]
42
43
  end
44
+
45
+ def boom(_request, _response)
46
+ 1 + "2"
47
+ end
43
48
  end
44
49
 
45
50
  describe handler, lita_handler: true do
@@ -82,6 +87,14 @@ describe handler, lita_handler: true do
82
87
  expect(response.status).to eq(200)
83
88
  expect(response.body).to eq("block")
84
89
  end
90
+
91
+ context "when the handler raises an exception" do
92
+ it "calls the error handler with the exception as argument" do
93
+ expect(registry.config.robot.error_handler).to receive(:call).with(instance_of(TypeError))
94
+
95
+ expect { http.get("/boom") }.to raise_error(TypeError, "String can't be coerced into Fixnum")
96
+ end
97
+ end
85
98
  end
86
99
 
87
100
  describe handler, lita_handler: true do
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ handler_class = Class.new(Lita::Handler) do
4
+ namespace "testclass"
5
+
6
+ def self.name
7
+ "Lita::Handlers::Test"
8
+ end
9
+ end
10
+
11
+ additional_handler_class = Class.new(Lita::Handler) do
12
+ namespace "testclass"
13
+
14
+ config :test_property, type: String, default: "a string"
15
+
16
+ def self.name
17
+ "Lita::Handlers::TestBase"
18
+ end
19
+ end
20
+
21
+ describe handler_class, lita_handler: true, additional_lita_handlers: additional_handler_class do
22
+ context 'when the "additional_lita_handlers" metadata is provided' do
23
+ it "loads additional handlers into the registry" do
24
+ expect(registry.handlers).to include(additional_handler_class)
25
+ end
26
+
27
+ it "populates config from additional handlers" do
28
+ expect(registry.config.handlers.testclass.test_property).to eq("a string")
29
+ end
30
+ end
31
+ end
@@ -176,6 +176,12 @@ describe Lita do
176
176
  described_class.run("path/to/config")
177
177
  end
178
178
 
179
+ it "calls config_finalized hooks" do
180
+ described_class.register_hook(:config_finalized, hook)
181
+ expect(hook).to receive(:call).with(config_path: "path/to/config")
182
+ described_class.run("path/to/config")
183
+ end
184
+
179
185
  it "raises if the configuration is not valid" do
180
186
  allow(validator).to receive(:call).and_raise(SystemExit)
181
187
 
@@ -76,6 +76,15 @@ en:
76
76
  to the root of the repository.
77
77
 
78
78
  Common open source software licenses can be found at http://choosealicense.com/.
79
+ badges_message: >-
80
+ If your plugin's Git repository will be hosted on GitHub, build status and code coverage
81
+ badges can be automatically added to your README.
82
+ badges_question: >-
83
+ Would you like to add these badges? ("yes" or "no", default is "no")
84
+ github_user_question: What is your GitHub username?
85
+ badges_reminder: >-
86
+ Remember, for badges to be displayed in your plugin's README, you must host your project on
87
+ GitHub. Additionally, you will need to configure the project on Travis CI and Coveralls.io.
79
88
  config:
80
89
  adapter_deprecated:
81
90
  config.adapter is deprecated and will be removed in Lita 5.0. Use config.adapters instead.
@@ -1,5 +1,16 @@
1
1
  # <%= config[:gem_name] %>
2
2
 
3
+ <%- if config[:badges] -%>
4
+ <%- if config[:travis] -%>
5
+ [![Build Status](https://travis-ci.org/<%= config[:github_user] %>/<%= config[:gem_name] %>.png?branch=master)](https://travis-ci.org/<%= config[:github_user] %>/<%= config[:gem_name] %>)
6
+ <%- end -%>
7
+ <%- if config[:coveralls] -%>
8
+ [![Coverage Status](https://coveralls.io/repos/<%= config[:github_user] %>/<%= config[:gem_name] %>/badge.png)](https://coveralls.io/r/<%= config[:github_user] %>/<%= config[:gem_name] %>)
9
+ <%- end -%>
10
+ <%- if config[:travis] || config[:coveralls] -%>
11
+
12
+ <%- end -%>
13
+ <%- end -%>
3
14
  TODO: Add a description of the plugin.
4
15
 
5
16
  ## Installation
@@ -27,7 +38,3 @@ TODO: Describe any configuration attributes the plugin exposes.
27
38
  ## Usage
28
39
 
29
40
  TODO: Describe the plugin's features and how to use them.
30
-
31
- ## License
32
-
33
- [MIT](http://opensource.org/licenses/MIT)
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.description = "TODO: Add a description"
7
7
  spec.summary = "TODO: Add a summary"
8
8
  spec.homepage = "TODO: Add a homepage"
9
- spec.license = "MIT"
9
+ spec.license = "TODO: Add a license"
10
10
  spec.metadata = { "lita_plugin_type" => "<%= config[:plugin_type] %>" }
11
11
 
12
12
  spec.files = `git ls-files`.split($/)
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.add_runtime_dependency "lita", ">= <%= config[:required_lita_version] %>"
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
20
21
  spec.add_development_dependency "rake"
21
22
  spec.add_development_dependency "rack-test"
22
23
  spec.add_development_dependency "rspec", ">= 3.0.0"
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.2.1
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -354,6 +354,7 @@ files:
354
354
  - spec/lita/plugin_builder_spec.rb
355
355
  - spec/lita/response_spec.rb
356
356
  - spec/lita/robot_spec.rb
357
+ - spec/lita/rspec/handler_spec.rb
357
358
  - spec/lita/rspec_spec.rb
358
359
  - spec/lita/source_spec.rb
359
360
  - spec/lita/template_resolver_spec.rb
@@ -430,6 +431,7 @@ test_files:
430
431
  - spec/lita/plugin_builder_spec.rb
431
432
  - spec/lita/response_spec.rb
432
433
  - spec/lita/robot_spec.rb
434
+ - spec/lita/rspec/handler_spec.rb
433
435
  - spec/lita/rspec_spec.rb
434
436
  - spec/lita/source_spec.rb
435
437
  - spec/lita/template_resolver_spec.rb