Skip to content

Commit

Permalink
Minor refactor for previous commit
Browse files Browse the repository at this point in the history
Add nocov around set_temporary_name, since this cannot be branch
covered on Ruby < 3.3.

Use begin/ensure in spec to ensure that the MyApp constant is
removed even if the spec fails.

Update CHANGELOG.
  • Loading branch information
jeremyevans committed Dec 27, 2023
1 parent cb65272 commit fa7481c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= master

* Set temporary name on Ruby 3.3 in middleware plugin for middleware class created (janko) (#344)

* Add break plugin, for using break inside a routing block to return from the block and keep routing (jeremyevans)

= 3.75.0 (2023-12-14)
Expand Down
2 changes: 2 additions & 0 deletions lib/roda/plugins/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class Forwarder
# and store +app+ as the next middleware to call.
def initialize(mid, app, *args, &block)
@mid = Class.new(mid)
# :nocov:
@mid.set_temporary_name("#{mid.name}(middleware)") if mid.name && RUBY_VERSION >= "3.3"
# :nocov:
if @mid.opts[:middleware_next_if_not_found]
@mid.plugin(:not_found, &NEXT_PROC)
end
Expand Down
15 changes: 9 additions & 6 deletions spec/plugin/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@ def call
end
body.must_equal 'anonymous'

Object.const_set(:MyApp, a)
app(:bare) do
use a
route {}
begin
Object.const_set(:MyApp, a)
app(:bare) do
use a
route {}
end
body.must_equal 'MyApp(middleware)'
ensure
Object.send(:remove_const, :MyApp)
end
body.must_equal 'MyApp(middleware)'
Object.send(:remove_const, :MyApp)
end if RUBY_VERSION >= "3.3"

it "should raise error if attempting to use options for Roda application that does not support configurable middleware" do
Expand Down

0 comments on commit fa7481c

Please sign in to comment.