From b9d5676b5ac462e1dc26b79551bb40b6cfbd8f01 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 3 Sep 2024 11:01:52 +0100 Subject: [PATCH] Merge pull request #2791 from rspec/cleanup-rails-6-1 Cleanup for versions 7 --- Changelog.md | 2 ++ Gemfile-rails-dependencies | 6 +--- example_app_generator/generate_app.rb | 2 +- .../spec/support/default_preview_path | 4 +-- .../spec/verify_mailer_preview_path_spec.rb | 13 +------- features/file_fixture.feature | 1 - .../generator_specs/integration_specs.feature | 21 ------------- features/support/rails_versions.rb | 15 ---------- .../integration/integration_generator.rb | 29 ------------------ .../scaffold/templates/controller_spec.rb | 15 ---------- .../rspec/scaffold/templates/request_spec.rb | 15 ---------- .../rails/example/rails_example_group.rb | 14 ++++----- script/update_rubygems_and_install_bundler | 14 +-------- .../integration/integration_generator_spec.rb | 14 --------- .../rspec/scaffold/scaffold_generator_spec.rb | 30 +++++-------------- .../rails/example/rails_example_group_spec.rb | 6 ++-- 16 files changed, 23 insertions(+), 178 deletions(-) delete mode 100644 features/generator_specs/integration_specs.feature delete mode 100644 features/support/rails_versions.rb delete mode 100644 lib/generators/rspec/integration/integration_generator.rb delete mode 100644 spec/generators/rspec/integration/integration_generator_spec.rb diff --git a/Changelog.md b/Changelog.md index cfb08704e..36535ef0e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ Bug Fixes: * Remove mutation of Rails constant in favour of public api. (Petrik de Heus, #2789) * Cleanup Rails scaffold for unsupported versions. (Matt Jankowski, #2790) +* Remove deprecated scaffold that was unintentionally included in 7.0.0 + (Jon Rowe, #2791) ### 7.0.0 / 2024-09-02 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.5...v7.0.0) diff --git a/Gemfile-rails-dependencies b/Gemfile-rails-dependencies index d8487f7fa..0d08d7663 100644 --- a/Gemfile-rails-dependencies +++ b/Gemfile-rails-dependencies @@ -21,11 +21,7 @@ def add_sqlite3_gem_dependency end end -if RUBY_VERSION.to_f < 2.7 - gem 'puma', '< 6.0.0' -else - gem 'puma' -end +gem 'puma' case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || '' when /main/ diff --git a/example_app_generator/generate_app.rb b/example_app_generator/generate_app.rb index 5ffdca72a..aaa727663 100644 --- a/example_app_generator/generate_app.rb +++ b/example_app_generator/generate_app.rb @@ -69,7 +69,7 @@ copy_file capybara_backport_path, 'spec/support/capybara.rb' - if Rails::VERSION::STRING > '7' && Rails::VERSION::STRING < '7.2' + if Rails::VERSION::STRING < '7.2' create_file 'app/assets/config/manifest.js' do "//= link application.css" end diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 7bfc2c5cf..6ce03ef52 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -37,9 +37,7 @@ require_file_stub 'config/environment' do module ExampleApp class Application < Rails::Application config.eager_load = false - if Rails::VERSION::STRING.to_f >= 7.0 - config.active_support.cache_format_version = 7.0 - end + config.active_support.cache_format_version = 7.0 # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false unless ENV['NO_ACTION_MAILER'] 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 b35b285fa..9f21bc01e 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -40,7 +40,7 @@ def capture_exec(*ops) if ENV['RAILS_VERSION'] == 'main' && Rails::VERSION::STRING == "8.0.0.alpha" before do - skip('This is broken on Rails main but is skipped for green builds of 7.1.x, please fix') + skip('This is broken on Rails main but is skipped for green builds, please fix') end end @@ -139,17 +139,6 @@ def have_no_preview(_opts = {}) ) ).to eq('test-host') end - - it 'handles action mailer not being available' do - skip "Rails 7 forces eager loading on CI, loads app/mailers and fails" if Rails::VERSION::STRING.to_f >= 7.0 - - expect( - capture_exec( - custom_env.merge('NO_ACTION_MAILER' => 'true'), - exec_script - ) - ).to have_no_preview - end end else context 'in the development environment' do diff --git a/features/file_fixture.feature b/features/file_fixture.feature index c6a765a53..2606c76e0 100644 --- a/features/file_fixture.feature +++ b/features/file_fixture.feature @@ -37,7 +37,6 @@ Feature: Using `file_fixture` When I run `rspec spec/lib/file_spec.rb` Then the examples should all pass - @rails_post_7 Scenario: Creating a ActiveStorage::Blob from a file fixture Given a file named "spec/fixtures/files/sample.txt" with: """ diff --git a/features/generator_specs/integration_specs.feature b/features/generator_specs/integration_specs.feature deleted file mode 100644 index ea9c14242..000000000 --- a/features/generator_specs/integration_specs.feature +++ /dev/null @@ -1,21 +0,0 @@ -Feature: Integration generator spec - - Scenario: Integration generator - When I run `bundle exec rails generate rspec:integration posts` - Then the features should pass - Then the output should contain: - """ - create spec/requests/posts_spec.rb - """ - - Scenario: Integration generator with customized `default-path` - Given a file named ".rspec" with: - """ - --default-path behaviour - """ - And I run `bundle exec rails generate rspec:integration posts` - Then the features should pass - Then the output should contain: - """ - create behaviour/requests/posts_spec.rb - """ diff --git a/features/support/rails_versions.rb b/features/support/rails_versions.rb deleted file mode 100644 index 95354a0b3..000000000 --- a/features/support/rails_versions.rb +++ /dev/null @@ -1,15 +0,0 @@ -def rails_version - string_version = ENV.fetch("RAILS_VERSION", "~> 7.0.0") - if string_version == "main" || string_version.nil? - Float::INFINITY - else - string_version[/\d[.-]\d/].tr('-', '.') - end -end - -Before "@rails_post_7" do |scenario| - if rails_version.to_f < 7.0 - warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}" - skip_this_scenario - end -end diff --git a/lib/generators/rspec/integration/integration_generator.rb b/lib/generators/rspec/integration/integration_generator.rb deleted file mode 100644 index ed281e832..000000000 --- a/lib/generators/rspec/integration/integration_generator.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'generators/rspec' -require 'rspec/core/warnings' - -module Rspec - module Generators - # @private - class IntegrationGenerator < Base - class_option :request_specs, - type: :boolean, - default: true, - desc: "Generate request specs" - - source_paths << File.expand_path('../request/templates', __dir__) - - def generate_request_spec - return unless options[:request_specs] - - RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/, ' ') - |The integration generator is deprecated - |and will be deleted in RSpec-Rails 7. - |Please use the request generator instead. - WARNING - - template 'request_spec.rb', - target_path('requests', "#{name.underscore.pluralize}_spec.rb") - end - end - end -end diff --git a/lib/generators/rspec/scaffold/templates/controller_spec.rb b/lib/generators/rspec/scaffold/templates/controller_spec.rb index 7f4320bd0..837e34e9b 100644 --- a/lib/generators/rspec/scaffold/templates/controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/controller_spec.rb @@ -90,17 +90,10 @@ end context "with invalid params" do - <% if Rails.version.to_f < 7.0 %> - it "returns a success response (i.e. to display the 'new' template)" do - post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - <% else %> it "renders a response with 422 status (i.e. to display the 'new' template)" do post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session expect(response).to have_http_status(:unprocessable_entity) end - <% end %> end end @@ -125,19 +118,11 @@ end context "with invalid params" do - <% if Rails.version.to_f < 7.0 %> - it "returns a success response (i.e. to display the 'edit' template)" do - <%= file_name %> = <%= class_name %>.create! valid_attributes - put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - <% else %> it "renders a response with 422 status (i.e. to display the 'edit' template)" do <%= file_name %> = <%= class_name %>.create! valid_attributes put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session expect(response).to have_http_status(:unprocessable_entity) end - <% end %> end end diff --git a/lib/generators/rspec/scaffold/templates/request_spec.rb b/lib/generators/rspec/scaffold/templates/request_spec.rb index 6d6fdab9e..b93e75f36 100644 --- a/lib/generators/rspec/scaffold/templates/request_spec.rb +++ b/lib/generators/rspec/scaffold/templates/request_spec.rb @@ -83,17 +83,10 @@ }.to change(<%= class_name %>, :count).by(0) end - <% if Rails.version.to_f < 7.0 %> - it "renders a successful response (i.e. to display the 'new' template)" do - post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes } - expect(response).to be_successful - end - <% else %> it "renders a response with 422 status (i.e. to display the 'new' template)" do post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - <% end %> end end @@ -119,19 +112,11 @@ end context "with invalid parameters" do - <% if Rails.version.to_f < 7.0 %> - it "renders a successful response (i.e. to display the 'edit' template)" do - <%= file_name %> = <%= class_name %>.create! valid_attributes - patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes } - expect(response).to be_successful - end - <% else %> it "renders a response with 422 status (i.e. to display the 'edit' template)" do <%= file_name %> = <%= class_name %>.create! valid_attributes patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - <% end %> end end diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index ed343de35..07c8ec421 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -2,10 +2,8 @@ # suite and ammeter. require 'rspec/rails/matchers' -if ::Rails::VERSION::MAJOR >= 7 - require 'active_support/current_attributes/test_helper' - require 'active_support/execution_context/test_helper' -end +require 'active_support/current_attributes/test_helper' +require 'active_support/execution_context/test_helper' module RSpec module Rails @@ -17,11 +15,9 @@ module RailsExampleGroup include RSpec::Rails::MinitestLifecycleAdapter include RSpec::Rails::MinitestAssertionAdapter include RSpec::Rails::FixtureSupport - if ::Rails::VERSION::MAJOR >= 7 - include RSpec::Rails::TaggedLoggingAdapter - include ActiveSupport::CurrentAttributes::TestHelper - include ActiveSupport::ExecutionContext::TestHelper - end + include RSpec::Rails::TaggedLoggingAdapter + include ActiveSupport::CurrentAttributes::TestHelper + include ActiveSupport::ExecutionContext::TestHelper end end end diff --git a/script/update_rubygems_and_install_bundler b/script/update_rubygems_and_install_bundler index c85e5dcc4..c2673e341 100755 --- a/script/update_rubygems_and_install_bundler +++ b/script/update_rubygems_and_install_bundler @@ -11,22 +11,10 @@ function is_ruby_3_plus { fi } -function is_ruby_26_plus { - if ruby -e "exit(RUBY_VERSION.to_f >= 2.6)"; then - return 0 - else - return 1 - fi -} - if is_ruby_3_plus; then gem update --no-document --system gem install --no-document bundler -elif is_ruby_26_plus; then +else gem update --no-document --system '3.4.22' gem install --no-document bundler -else - echo "Warning installing older versions of Rubygems / Bundler" - gem update --system '3.3.26' - gem install bundler -v '2.3.26' fi diff --git a/spec/generators/rspec/integration/integration_generator_spec.rb b/spec/generators/rspec/integration/integration_generator_spec.rb deleted file mode 100644 index e0777bb85..000000000 --- a/spec/generators/rspec/integration/integration_generator_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Generators are not automatically loaded by Rails -require 'generators/rspec/integration/integration_generator' -require 'support/generators' -require 'rspec/core/warnings' - -RSpec.describe Rspec::Generators::IntegrationGenerator, type: :generator do - setup_default_destination - it_behaves_like "a request spec generator" - - it 'is deprecated' do - expect(RSpec).to receive(:warn_deprecation) - run_generator %w[posts] - end -end diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index 62e6db5ef..3c663dc83 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -26,21 +26,12 @@ .and(contain(/"redirects to the \w+ list"/)) ) - if ::Rails::VERSION::STRING >= '7.0.0' - expect( - filename - ).to( - contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/) - .and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/)) - ) - else - expect( - filename - ).to( - contain(/renders a successful response \(i.e. to display the 'new' template\)/) - .and(contain(/renders a successful response \(i.e. to display the 'edit' template\)/)) - ) - end + expect( + filename + ).to( + contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/) + .and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/)) + ) end end @@ -105,13 +96,8 @@ .and(contain(/"redirects to the \w+ list"/)) ) - if ::Rails::VERSION::STRING >= '7.0.0' - expect(filename).to contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/) - .and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/)) - else - expect(filename).to contain(/returns a success response \(i.e. to display the 'new' template\)/) - .and(contain(/returns a success response \(i.e. to display the 'edit' template\)/)) - end + expect(filename).to contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/) + .and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/)) expect(filename).not_to contain(/"renders a JSON response with the new \w+"/) expect(filename).not_to contain(/"renders a JSON response with errors for the new \w+"/) diff --git a/spec/rspec/rails/example/rails_example_group_spec.rb b/spec/rspec/rails/example/rails_example_group_spec.rb index 7dbe13788..d21dc2c3b 100644 --- a/spec/rspec/rails/example/rails_example_group_spec.rb +++ b/spec/rspec/rails/example/rails_example_group_spec.rb @@ -1,10 +1,10 @@ module RSpec::Rails RSpec.describe RailsExampleGroup do - it 'supports tagged_logger', if: ::Rails::VERSION::MAJOR >= 7 do + it 'supports tagged_logger' do expect(described_class.private_instance_methods).to include(:tagged_logger) end - it 'does not leak context between example groups', if: ::Rails::VERSION::MAJOR >= 7 do + it 'does not leak context between example groups' do groups = [ RSpec::Core::ExampleGroup.describe("A group") do @@ -31,7 +31,7 @@ module RSpec::Rails expect(results).to all be true end - it 'will not leak ActiveSupport::CurrentAttributes between examples', if: ::Rails::VERSION::MAJOR >= 7 do + it 'will not leak ActiveSupport::CurrentAttributes between examples' do group = RSpec::Core::ExampleGroup.describe("A group", order: :defined) do include RSpec::Rails::RailsExampleGroup