From ed467f43bff359ec38207cb69929adc511d7f906 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 23 Oct 2023 08:34:37 +0100 Subject: [PATCH 1/6] Silence deprecation about cache format --- example_app_generator/spec/support/default_preview_path | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 21f37a95e..14057c048 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -37,6 +37,9 @@ require_file_stub 'config/environment' do module ExampleApp class Application < Rails::Application config.eager_load = false + if Rails::VERSION::STRING.start_with?('7') + config.active_support.cache_format_version = 7.0 + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false unless ENV['NO_ACTION_MAILER'] From 0dbdd6fad21e43db8c53f525c01135b38033a19f Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 23 Oct 2023 08:35:23 +0100 Subject: [PATCH 2/6] Handle preview_paths in Rails 7.1 --- .../spec/support/default_preview_path | 13 +++++-- .../spec/verify_mailer_preview_path_spec.rb | 34 +++++++++++++------ lib/rspec-rails.rb | 14 ++++++-- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 14057c048..dfae9d80e 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -43,9 +43,12 @@ require_file_stub 'config/environment' do # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false unless ENV['NO_ACTION_MAILER'] - if ENV['CUSTOM_PREVIEW_PATH'] - config.action_mailer.preview_path = ENV['CUSTOM_PREVIEW_PATH'] + if Rails::VERSION::STRING.start_with?('7.1') + config.action_mailer.preview_paths = [ENV['CUSTOM_PREVIEW_PATH']] + else + config.action_mailer.preview_path = ENV['CUSTOM_PREVIEW_PATH'] + end end if ENV['SHOW_PREVIEWS'] config.action_mailer.show_previews = (ENV['SHOW_PREVIEWS'] == 'true') @@ -66,7 +69,11 @@ exit if ENV['NO_ACTION_MAILER'] if ENV['DEFAULT_URL'] puts ActionMailer::Base.default_url_options[:host] elsif defined?(::ActionMailer::Preview) - puts Rails.application.config.action_mailer.preview_path + if Rails::VERSION::STRING.start_with?('7.1') + puts Rails.application.config.action_mailer.preview_paths + else + puts Rails.application.config.action_mailer.preview_path + end end # This will force the loading of ActionMailer settings to ensure we do not diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index 318336535..507d93381 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -30,12 +30,26 @@ def capture_exec(*ops) CaptureExec.new(out, $?.exitstatus) end - def have_no_preview - have_attributes(io: be_blank, exit_status: 0) - end + if Rails::VERSION::STRING.start_with?('7.1') + let(:expected_custom_path) { "/custom/path\n#{::Rails.root}/test/mailers/previews" } + let(:expected_rspec_path) { "#{::Rails.root}/spec/mailers/previews\n#{::Rails.root}/test/mailers/previews" } + + def have_no_preview(opts = {}) + expected_io = + if opts[:actually_blank] + be_blank + else + "#{::Rails.root}/test/mailers/previews" + end + have_attributes(io: expected_io, exit_status: 0) + end + else + let(:expected_custom_path) { '/custom/path' } + let(:expected_rspec_path) { "#{::Rails.root}/spec/mailers/previews" } - before do - skip("Currently broken for unknown reasons") + def have_no_preview(_opts = {}) + have_attributes(io: be_blank, exit_status: 0) + end end let(:exec_script) { @@ -49,9 +63,7 @@ def have_no_preview it 'sets the preview path to the default rspec path' do skip "this spec fails singularly on JRuby due to weird env things" if RUBY_ENGINE == "jruby" - expect(capture_exec(custom_env, exec_script)).to eq( - "#{::Rails.root}/spec/mailers/previews" - ) + expect(capture_exec(custom_env, exec_script)).to eq(expected_rspec_path) end it 'respects the setting from `show_previews`' do @@ -69,7 +81,7 @@ def have_no_preview custom_env.merge('CUSTOM_PREVIEW_PATH' => '/custom/path'), exec_script ) - ).to eq('/custom/path') + ).to eq(expected_custom_path) end it 'allows initializers to set options' do @@ -87,7 +99,7 @@ def have_no_preview custom_env.merge('NO_ACTION_MAILER' => 'true'), exec_script ) - ).to have_no_preview + ).to have_no_preview(actually_blank: true) end end @@ -102,7 +114,7 @@ def have_no_preview it 'respects the setting from `show_previews`' do expect( capture_exec(custom_env.merge('SHOW_PREVIEWS' => 'true'), exec_script) - ).to eq("#{::Rails.root}/spec/mailers/previews") + ).to eq(expected_rspec_path) end it 'allows initializers to set options' do diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index 45592fbd8..9c16b36a2 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -47,10 +47,18 @@ def config_preview_path?(options) end end - def config_default_preview_path(options) - return unless options.preview_path.blank? + if ::Rails::VERSION::STRING >= "7.1.0" + def config_default_preview_path(options) + return unless options.preview_paths.empty? - options.preview_path = "#{::Rails.root}/spec/mailers/previews" + options.preview_paths << "#{::Rails.root}/spec/mailers/previews" + end + else + def config_default_preview_path(options) + return unless options.preview_path.blank? + + options.preview_path = "#{::Rails.root}/spec/mailers/previews" + end end def supports_action_mailer_previews?(config) From d44f007f837f43b7854a61835ef03594934dd5f6 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 13 Nov 2023 22:59:02 +0000 Subject: [PATCH 3/6] Change version checks to use floats --- example_app_generator/spec/support/default_preview_path | 4 ++-- example_app_generator/spec/verify_mailer_preview_path_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index dfae9d80e..740b98af4 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -37,14 +37,14 @@ require_file_stub 'config/environment' do module ExampleApp class Application < Rails::Application config.eager_load = false - if Rails::VERSION::STRING.start_with?('7') + if Rails::VERSION::STRING.to_f >= 7.0 config.active_support.cache_format_version = 7.0 end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false unless ENV['NO_ACTION_MAILER'] if ENV['CUSTOM_PREVIEW_PATH'] - if Rails::VERSION::STRING.start_with?('7.1') + if Rails::VERSION::STRING.to_f >= 7.1 config.action_mailer.preview_paths = [ENV['CUSTOM_PREVIEW_PATH']] else config.action_mailer.preview_path = ENV['CUSTOM_PREVIEW_PATH'] diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index 507d93381..a2e7ea5a9 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -30,7 +30,7 @@ def capture_exec(*ops) CaptureExec.new(out, $?.exitstatus) end - if Rails::VERSION::STRING.start_with?('7.1') + if Rails::VERSION::STRING.to_f >= 7.1 let(:expected_custom_path) { "/custom/path\n#{::Rails.root}/test/mailers/previews" } let(:expected_rspec_path) { "#{::Rails.root}/spec/mailers/previews\n#{::Rails.root}/test/mailers/previews" } From dbaa79f29e1254b2fa4e156ed95a8c2a8c7f7188 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 13 Nov 2023 22:59:26 +0000 Subject: [PATCH 4/6] Rework exit status capturing --- .../spec/support/default_preview_path | 3 ++- .../spec/verify_mailer_preview_path_spec.rb | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 740b98af4..902f0b9df 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -65,7 +65,7 @@ require_file_stub 'config/environment' do Rails.application.initialize! end -exit if ENV['NO_ACTION_MAILER'] +exit(0) if ENV['NO_ACTION_MAILER'] if ENV['DEFAULT_URL'] puts ActionMailer::Base.default_url_options[:host] elsif defined?(::ActionMailer::Preview) @@ -79,3 +79,4 @@ end # This will force the loading of ActionMailer settings to ensure we do not # accidentally set something we should not ActionMailer::Base.smtp_settings +exit 0 diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index a2e7ea5a9..f27bbb847 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -17,9 +17,17 @@ def as_commandline(ops) def capture_exec(*ops) ops << { err: [:child, :out] } - io = IO.popen(ops) + lines = [] + + _process = + IO.popen(ops) do |io| + while (line = io.gets) + lines << line + end + end + # Necessary to ignore warnings from Rails code base - out = io.readlines + out = lines .reject { |line| line =~ /warning: circular argument reference/ } .reject { |line| line =~ /Gem::Specification#rubyforge_project=/ } .reject { |line| line =~ /DEPRECATION WARNING/ } From 829c436776b45cf9e3c521bc34a0725810e65d44 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 14 Nov 2023 09:06:56 +0000 Subject: [PATCH 5/6] Prevent zeitwerk check from erroring on 6.1 --- .../no_active_record/config/initializers/zeitwerk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_app_generator/no_active_record/config/initializers/zeitwerk.rb b/example_app_generator/no_active_record/config/initializers/zeitwerk.rb index c0c557c68..b78def42e 100644 --- a/example_app_generator/no_active_record/config/initializers/zeitwerk.rb +++ b/example_app_generator/no_active_record/config/initializers/zeitwerk.rb @@ -1,3 +1,3 @@ -if Rails.autoloaders.respond_to?(:main) +if Rails.autoloaders.respond_to?(:main) && Rails.autoloaders.main.respond_to?(:ignore) Rails.autoloaders.main.ignore('lib/rails/generators/in_memory/model/model_generator.rb') end From b84484b1b1ced79b51fef1b46f7f4d1b62ed2da3 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 14 Nov 2023 13:02:49 +0000 Subject: [PATCH 6/6] Skip specs on Rails main --- .../spec/verify_mailer_preview_path_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index f27bbb847..50f145497 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -38,6 +38,12 @@ def capture_exec(*ops) CaptureExec.new(out, $?.exitstatus) end + if ENV['RAILS_VERSION'] == 'main' && Rails::VERSION::STRING == "7.2.0.alpha" + before do + skip('This is broken on Rails main but is skipped for green builds of 7.1.x, please fix') + end + end + if Rails::VERSION::STRING.to_f >= 7.1 let(:expected_custom_path) { "/custom/path\n#{::Rails.root}/test/mailers/previews" } let(:expected_rspec_path) { "#{::Rails.root}/spec/mailers/previews\n#{::Rails.root}/test/mailers/previews" }