8484
8585 end
8686
87+ it "should have defined Rails stub tests" do
88+ expect ( File . foreach ( __FILE__ ) . select { |line | line . include? ( "describe" ) } ) . to include ( /^ describe.*lib: :#{ CURRENT_LIB } / ) ,
89+ "Expected rails stub tests to be defined for #{ CURRENT_LIB } inside integration_spec.rb"
90+ expect ( File . exist? ( File . join ( STUB_DIR , CURRENT_LIB . to_s ) ) ) . to be ( true ) ,
91+ "Expected rails stub dir for #{ CURRENT_LIB . to_s } to exist at #{ File . join ( STUB_DIR , CURRENT_LIB . to_s ) . inspect } "
92+ end if CURRENT_LIB . to_s . include? ( 'rails' )
93+
8794 shared_examples_for 'a rails app' , :shared => true do
8895
96+ base_path = "file://#{ STUB_DIR } /#{ CURRENT_LIB . to_s } "
97+
8998 let ( :servlet_context ) do
90- new_servlet_context ( base_path ) . tap { |servlet_context | prepare_servlet_context ( servlet_context ) }
99+ new_servlet_context ( base_path ) . tap { |servlet_context | prepare_servlet_context ( servlet_context , base_path ) }
91100 end
92101
93- it "initializes (pooling by default)" do
94- listener = org . jruby . rack . rails . RailsServletContextListener . new
95- listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
102+ context "runtime" do
96103
97- rack_factory = servlet_context . getAttribute ( "rack.factory" )
98- expect ( rack_factory ) . to be_a ( RackApplicationFactory )
99- expect ( rack_factory ) . to be_a ( PoolingRackApplicationFactory )
100- expect ( rack_factory ) . to respond_to ( :realFactory )
101- expect ( rack_factory . realFactory ) . to be_a ( RailsRackApplicationFactory )
104+ it "initializes (pooling by default)" do
105+ listener = org . jruby . rack . rails . RailsServletContextListener . new
106+ listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
102107
103- expect ( servlet_context . getAttribute ( "rack.context" ) ) . to be_a ( RackContext )
104- expect ( servlet_context . getAttribute ( "rack.context" ) ) . to be_a ( ServletRackContext )
108+ rack_factory = servlet_context . getAttribute ( "rack.factory" )
109+ expect ( rack_factory ) . to be_a ( RackApplicationFactory )
110+ expect ( rack_factory ) . to be_a ( PoolingRackApplicationFactory )
111+ expect ( rack_factory ) . to respond_to ( :realFactory )
112+ expect ( rack_factory . realFactory ) . to be_a ( RailsRackApplicationFactory )
105113
106- expect ( rack_factory . getApplication ) . to be_a ( DefaultRackApplication )
107- end
114+ expect ( servlet_context . getAttribute ( "rack.context" ) ) . to be_a ( RackContext )
115+ expect ( servlet_context . getAttribute ( "rack.context" ) ) . to be_a ( ServletRackContext )
108116
109- it "initializes threadsafe!" do
110- servlet_context . addInitParameter ( 'jruby.max.runtimes' , '1' )
117+ expect ( rack_factory . getApplication ) . to be_a ( DefaultRackApplication )
118+ end
111119
112- listener = org . jruby . rack . rails . RailsServletContextListener . new
113- listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
120+ it "initializes threadsafe!" do
121+ servlet_context . addInitParameter ( 'jruby.max.runtimes' , '1' )
114122
115- rack_factory = servlet_context . getAttribute ( "rack.factory" )
116- expect ( rack_factory ) . to be_a ( RackApplicationFactory )
117- expect ( rack_factory ) . to be_a ( SharedRackApplicationFactory )
118- expect ( rack_factory . realFactory ) . to be_a ( RailsRackApplicationFactory )
123+ listener = org . jruby . rack . rails . RailsServletContextListener . new
124+ listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
119125
120- expect ( rack_factory . getApplication ) . to be_a ( DefaultRackApplication )
121- end
122- end
123-
124- describe 'rails 7.2' , lib : :rails72 do
126+ rack_factory = servlet_context . getAttribute ( "rack.factory" )
127+ expect ( rack_factory ) . to be_a ( RackApplicationFactory )
128+ expect ( rack_factory ) . to be_a ( SharedRackApplicationFactory )
129+ expect ( rack_factory . realFactory ) . to be_a ( RailsRackApplicationFactory )
125130
126- before ( :all ) do
127- name = :rails72 # copy_gemfile :
128- raise "Environment variable BUNDLE_GEMFILE seems to not contain #{ name . to_s } " unless ENV [ 'BUNDLE_GEMFILE' ] &.include? ( name . to_s )
129- FileUtils . cp ENV [ 'BUNDLE_GEMFILE' ] , File . join ( STUB_DIR , "#{ name } /Gemfile" )
130- FileUtils . cp "#{ ENV [ 'BUNDLE_GEMFILE' ] } .lock" , File . join ( STUB_DIR , "#{ name } /Gemfile.lock" )
131- Dir . chdir File . join ( STUB_DIR , name . to_s )
131+ expect ( rack_factory . getApplication ) . to be_a ( DefaultRackApplication )
132+ end
132133 end
133134
134- def base_path ; "#{ STUB_DIR } /rails72" end
135-
136- it_should_behave_like 'a rails app'
137-
138135 context "initialized" do
139136
137+ before ( :all ) { copy_gemfile }
138+
140139 before ( :all ) do
141140 initialize_rails ( 'production' , "file://#{ base_path } " ) do |servlet_context , _ |
142- prepare_servlet_context ( servlet_context )
141+ prepare_servlet_context ( servlet_context , base_path )
143142 end
144143 end
145- after ( :all ) { restore_rails }
144+ after ( :all ) { restore_rails }
146145
147146 it "loaded rack ~> 2.2.0" do
148147 @runtime = @rack_factory . getApplication . getRuntime
@@ -155,18 +154,27 @@ def base_path; "#{STUB_DIR}/rails72" end
155154 should_eval_as_not_nil "defined?(Rails)"
156155 should_eval_as_not_nil "Rails.logger"
157156
158- # Rails 7.x wraps the default in a ActiveSupport::BroadcastLogger
159- should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::BroadcastLogger" , true
160- should_eval_as_eql_to "Rails.logger.broadcasts.size" , 1
161- should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? JRuby::Rack::Logger" , true
162- # NOTE: TaggedLogging is a module that extends the logger instance:
163- should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? ActiveSupport::TaggedLogging" , true
164-
165157 # production.rb: config.log_level = 'info'
166158 should_eval_as_eql_to "Rails.logger.level" , Logger ::INFO
167- should_eval_as_eql_to "Rails.logger.broadcasts.first.level" , Logger ::INFO
168159
169- unwrap_logger = "logger = Rails.logger.broadcasts.first;"
160+ # Rails 7.1+ wraps the default in a ActiveSupport::BroadcastLogger
161+ if Rails ::VERSION ::STRING < '7.1'
162+ should_eval_as_eql_to "Rails.logger.is_a? JRuby::Rack::Logger" , true
163+ should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::TaggedLogging" , true
164+ unwrap_logger = "logger = Rails.logger;"
165+ else
166+ should_eval_as_not_nil "defined?(ActiveSupport::BroadcastLogger)"
167+ should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::BroadcastLogger" , true
168+ should_eval_as_eql_to "Rails.logger.broadcasts.size" , 1
169+ should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? JRuby::Rack::Logger" , true
170+ # NOTE: TaggedLogging is a module that extends the logger instance:
171+ should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? ActiveSupport::TaggedLogging" , true
172+
173+ should_eval_as_eql_to "Rails.logger.broadcasts.first.level" , Logger ::INFO
174+
175+ unwrap_logger = "logger = Rails.logger.broadcasts.first;"
176+ end
177+
170178 # sanity check logger-silence works:
171179 should_eval_as_eql_to "#{ unwrap_logger } logger.silence { logger.warn('from-integration-spec') }" , true
172180
@@ -178,9 +186,41 @@ def base_path; "#{STUB_DIR}/rails72" end
178186 should_eval_as_eql_to "Rails.public_path.to_s" , "#{ base_path } /public"
179187 end
180188
189+ it "disables rack's chunked support (by default)" do
190+ @runtime = @rack_factory . getApplication . getRuntime
191+ expect_to_have_monkey_patched_chunked
192+ end
181193 end
182194 end
183195
196+ describe 'rails 5.0' , lib : :rails50 do
197+ it_should_behave_like 'a rails app'
198+ end
199+
200+ describe 'rails 5.2' , lib : :rails52 do
201+ it_should_behave_like 'a rails app'
202+ end
203+
204+ describe 'rails 6.0' , lib : :rails60 do
205+ it_should_behave_like 'a rails app'
206+ end
207+
208+ describe 'rails 6.1' , lib : :rails61 do
209+ it_should_behave_like 'a rails app'
210+ end
211+
212+ describe 'rails 7.0' , lib : :rails70 do
213+ it_should_behave_like 'a rails app'
214+ end
215+
216+ describe 'rails 7.1' , lib : :rails71 do
217+ it_should_behave_like 'a rails app'
218+ end
219+
220+ describe 'rails 7.2' , lib : :rails72 do
221+ it_should_behave_like 'a rails app'
222+ end
223+
184224 def expect_to_have_monkey_patched_chunked
185225 @runtime . evalScriptlet "require 'rack/chunked'"
186226 script = %{
@@ -215,11 +255,11 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
215255
216256 def new_servlet_context ( base_path = nil )
217257 servlet_context = org . jruby . rack . mock . RackLoggingMockServletContext . new base_path
218- servlet_context . logger = raise_logger ( : WARN) . tap { |logger | logger . setEnabled ( false ) }
258+ servlet_context . logger = raise_logger ( ' WARN' ) . tap { |logger | logger . setEnabled ( false ) }
219259 servlet_context
220260 end
221261
222- def prepare_servlet_context ( servlet_context )
262+ def prepare_servlet_context ( servlet_context , base_path )
223263 set_compat_version servlet_context
224264 servlet_context . addInitParameter ( 'rails.root' , base_path )
225265 servlet_context . addInitParameter ( 'jruby.rack.layout_class' , 'FileSystemLayout' )
@@ -232,10 +272,12 @@ def set_compat_version(servlet_context = @servlet_context); require 'jruby'
232272
233273 GEMFILES_DIR = File . expand_path ( '../../../gemfiles' , STUB_DIR )
234274
235- def copy_gemfile ( name )
236- # e.g. 'rails30'
237- FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile" ) , File . join ( STUB_DIR , "#{ name } /WEB-INF/Gemfile" )
238- FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile.lock" ) , File . join ( STUB_DIR , "#{ name } /WEB-INF/Gemfile.lock" )
275+ def copy_gemfile
276+ name = CURRENT_LIB . to_s
277+ raise "Environment variable BUNDLE_GEMFILE seems to not contain #{ name } " unless ENV [ 'BUNDLE_GEMFILE' ] &.include? ( name )
278+ FileUtils . cp ENV [ 'BUNDLE_GEMFILE' ] , File . join ( STUB_DIR , "#{ name } /Gemfile" )
279+ FileUtils . cp "#{ ENV [ 'BUNDLE_GEMFILE' ] } .lock" , File . join ( STUB_DIR , "#{ name } /Gemfile.lock" )
280+ Dir . chdir File . join ( STUB_DIR , name )
239281 end
240282
241283 ENV_COPY = ENV . to_h
0 commit comments