diff --git a/CHANGELOG b/CHANGELOG index dbf32877..d93ef0f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/roda/plugins/middleware.rb b/lib/roda/plugins/middleware.rb index b0d15b97..81349d2d 100644 --- a/lib/roda/plugins/middleware.rb +++ b/lib/roda/plugins/middleware.rb @@ -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 diff --git a/spec/plugin/middleware_spec.rb b/spec/plugin/middleware_spec.rb index 9eca23ab..dd98478e 100644 --- a/spec/plugin/middleware_spec.rb +++ b/spec/plugin/middleware_spec.rb @@ -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