From 33702c037a4d9e18c469443b5922fcff2a8d7571 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 17 Jul 2022 22:14:51 +0300 Subject: [PATCH 1/5] Use the latest Cucumber Originally: > cucumber 3.2 would run on Ruby 2.2, 2.3 and 2.4 But Rails 6.1 and we only support Ruby 2.5+, so this is not needed. --- rspec-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index d285a9008..3e4ac7056 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -58,5 +58,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'ammeter', '~> 1.1.5' s.add_development_dependency 'aruba', '~> 0.14.12' - s.add_development_dependency 'cucumber', '>= 3.2', '!= 4.0.0', '< 8.0.0' + s.add_development_dependency 'cucumber', '~> 7.0' end From 00e59fe39dbdb4a2c46d65298cacf96bf09aaed2 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 17 Jul 2022 22:15:49 +0300 Subject: [PATCH 2/5] Mute annoying message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ┌──────────────────────────────────────────────────────────────────────────────┐ │ Share your Cucumber Report with your team at https://reports.cucumber.io │ │ To disable this message, specify CUCUMBER_PUBLISH_QUIET=true or use the │ ... │ --publish-quiet option. You can also add this to your cucumber.yml: │ │ default: --publish-quiet │ └──────────────────────────────────────────────────────────────────────────────┘ Now we can. Previously, this would break as previous Cucumber versions didn't know about this option flag. --- cucumber.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cucumber.yml b/cucumber.yml index 161eaa7c3..bfcd976ea 100644 --- a/cucumber.yml +++ b/cucumber.yml @@ -1,3 +1,3 @@ -default: --require features --format progress --tags 'not @wip' -pretty: --require features --format pretty --tags 'not @wip' -wip: --require features --tags @wip +default: --publish-quiet --require features --format progress --tags 'not @wip' +pretty: --publish-quiet --require features --format pretty --tags 'not @wip' +wip: --publish-quiet --require features --tags @wip From a67fb9ddd613ad2bb96d4ebaceabbe83993282a2 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 17 Jul 2022 22:22:52 +0300 Subject: [PATCH 3/5] Simplify sqlite3 dependency The comment still stands https://github.com/rails/rails/blob/9994d38bc6c1a8662e510d26c0e9ca8c24ab1189/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L13 --- Gemfile | 1 - Gemfile-rails-dependencies | 3 +++ Gemfile-sqlite-dependencies | 20 ------------------- .../config/initializers/sqlite3_fix.rb | 3 --- example_app_generator/generate_app.rb | 14 ++----------- snippets/avoid_fixture_name_collision.rb | 1 - snippets/use_active_record_false.rb | 1 - 7 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 Gemfile-sqlite-dependencies delete mode 100644 example_app_generator/config/initializers/sqlite3_fix.rb diff --git a/Gemfile b/Gemfile index 4ed27f867..e7e88b000 100644 --- a/Gemfile +++ b/Gemfile @@ -29,5 +29,4 @@ end custom_gemfile = File.expand_path('Gemfile-custom', __dir__) eval_gemfile custom_gemfile if File.exist?(custom_gemfile) -eval_gemfile 'Gemfile-sqlite-dependencies' eval_gemfile 'Gemfile-rails-dependencies' diff --git a/Gemfile-rails-dependencies b/Gemfile-rails-dependencies index 1e29eb66a..7308a48c5 100644 --- a/Gemfile-rails-dependencies +++ b/Gemfile-rails-dependencies @@ -11,6 +11,9 @@ def add_net_gems_dependency end end +# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4` +gem 'sqlite3', '~> 1.4', platforms: [:ruby] + case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || '' when /main/ gem "rails", :git => "https://github.com/rails/rails.git" diff --git a/Gemfile-sqlite-dependencies b/Gemfile-sqlite-dependencies deleted file mode 100644 index f7ab236d6..000000000 --- a/Gemfile-sqlite-dependencies +++ /dev/null @@ -1,20 +0,0 @@ -version_file = File.expand_path('.rails-version', __dir__) -RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || "" - -MAJOR = - case RAILS_VERSION - when /5-2-stable/ - 5 - when /main/, /stable/, nil, false, '' - 6 - else - /(\d+)[\.|-]\d+/.match(RAILS_VERSION).captures.first.to_i - end - -if MAJOR >= 6 -# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4` - gem 'sqlite3', '~> 1.4', platforms: [:ruby] -else -# Similarly, Rails 5.0 only supports '~> 1.3.6'. Rails 5.1-5.2 support '~> 1.3', '>= 1.3.6' - gem 'sqlite3', '~> 1.3.6', platforms: [:ruby] -end diff --git a/example_app_generator/config/initializers/sqlite3_fix.rb b/example_app_generator/config/initializers/sqlite3_fix.rb deleted file mode 100644 index 96ea148ac..000000000 --- a/example_app_generator/config/initializers/sqlite3_fix.rb +++ /dev/null @@ -1,3 +0,0 @@ -if Rails.application.config.respond_to?(:active_record) && RUBY_ENGINE != "jruby" - Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true -end diff --git a/example_app_generator/generate_app.rb b/example_app_generator/generate_app.rb index 08ecbf2f6..c0d8625c3 100644 --- a/example_app_generator/generate_app.rb +++ b/example_app_generator/generate_app.rb @@ -11,7 +11,6 @@ 'ci_retry_bundle_install.sh' ) function_script_file = File.join(rspec_rails_repo_path, 'script/functions.sh') -sqlite_initializer = File.join(rspec_rails_repo_path, "example_app_generator/config/initializers/sqlite3_fix.rb") in_root do prepend_to_file "Rakefile", "require 'active_support/all'" @@ -36,23 +35,14 @@ EOT end - if Rails::VERSION::STRING >= '6' - # sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4` - gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'" - else - # Similarly, Rails 5.0 only supports '~> 1.3.6'. Rails 5.1-5.2 support '~> 1.3', '>= 1.3.6' - gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'" - end + # sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4` + gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'" # webdrivers 4 up until 4.3.0 don't specify `required_ruby_version`, but contain # Ruby 2.2-incompatible syntax (safe navigation). # That basically means we use pre-4.0 for Ruby 2.2, and 4.3+ for newer Rubies. gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers', '!= 4.0.0', '!= 4.0.1', '!= 4.1.0', '!= 4.1.1', '!= 4.1.2', '!= 4.1.3', '!= 4.2.0'" - if Rails::VERSION::STRING < '6' - copy_file sqlite_initializer, 'config/initializers/sqlite3_fix.rb' - end - if RUBY_ENGINE == "jruby" gsub_file "Gemfile", /.*jdbc.*/, '' end diff --git a/snippets/avoid_fixture_name_collision.rb b/snippets/avoid_fixture_name_collision.rb index 8f1768acc..047d5c218 100644 --- a/snippets/avoid_fixture_name_collision.rb +++ b/snippets/avoid_fixture_name_collision.rb @@ -20,7 +20,6 @@ # Those Gemfiles carefully pick the right versions depending on # settings in the ENV, `.rails-version` and `maintenance-branch`. Dir.chdir('..') do - eval_gemfile 'Gemfile-sqlite-dependencies' # This Gemfile expects `maintenance-branch` file to be present # in the current directory. eval_gemfile 'Gemfile-rspec-dependencies' diff --git a/snippets/use_active_record_false.rb b/snippets/use_active_record_false.rb index 296522308..705af8a39 100644 --- a/snippets/use_active_record_false.rb +++ b/snippets/use_active_record_false.rb @@ -20,7 +20,6 @@ # Those Gemfiles carefully pick the right versions depending on # settings in the ENV, `.rails-version` and `maintenance-branch`. Dir.chdir('..') do - eval_gemfile 'Gemfile-sqlite-dependencies' # This Gemfile expects `maintenance-branch` file to be present # in the current directory. eval_gemfile 'Gemfile-rspec-dependencies' From 229f5f7ca9c0de0c7bca452450416d988f7cf612 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 17 Jul 2022 23:21:22 +0300 Subject: [PATCH 4/5] Remove version-specific checks for unsupported Rails/Ruby --- Gemfile | 15 ++----- README_DEV.md | 2 +- .../generate_action_mailer_specs.rb | 7 +-- example_app_generator/generate_app.rb | 14 +----- .../spec/support/default_preview_path | 8 ++-- .../spec/verify_custom_renderers_spec.rb | 6 --- features/README.md | 9 ++-- features/channel_specs/channel_spec.feature | 1 - .../anonymous_controller.feature | 37 ---------------- .../controller_specs/controller_spec.feature | 25 ----------- features/mailbox_specs/mailbox_spec.feature | 1 - .../matchers/have_broadcasted_matcher.feature | 1 - .../have_enqueued_mail_matcher.feature | 2 - .../matchers/have_stream_from_matcher.feature | 1 - features/request_specs/request_spec.feature | 22 ---------- features/support/rails_versions.rb | 22 ---------- features/upgrade/README.md | 6 +++ lib/rspec-rails.rb | 6 +-- .../rails/example/system_example_group.rb | 13 +++--- lib/rspec/rails/feature_check.rb | 2 +- .../rails/fixture_file_upload_support.rb | 43 ++++++------------- lib/rspec/rails/vendor/capybara.rb | 4 +- lib/rspec/rails/view_assigns.rb | 18 -------- lib/rspec/rails/view_rendering.rb | 10 +---- .../rails/fixture_file_upload_support_spec.rb | 6 +-- spec/rspec/rails/fixture_support_spec.rb | 2 +- spec/rspec/rails/matchers/active_job_spec.rb | 24 +++++------ 27 files changed, 58 insertions(+), 249 deletions(-) delete mode 100644 features/support/rails_versions.rb diff --git a/Gemfile b/Gemfile index e7e88b000..afec6680d 100644 --- a/Gemfile +++ b/Gemfile @@ -12,19 +12,10 @@ group :documentation do gem 'relish', '~> 0.7.1' end -gem 'rake', '> 12' - -if RUBY_VERSION.to_f >= 2.3 - gem 'rubocop', '~> 0.80.1' -end - gem 'capybara' - -if RUBY_VERSION.to_f >= 2.3 - gem 'ffi', '~> 1.15.5' -else - gem 'ffi', '~> 1.12.0' -end +gem 'ffi', '~> 1.15.5' +gem 'rake', '> 12' +gem 'rubocop', '~> 0.80.1' custom_gemfile = File.expand_path('Gemfile-custom', __dir__) eval_gemfile custom_gemfile if File.exist?(custom_gemfile) diff --git a/README_DEV.md b/README_DEV.md index 8c01e824e..b9ea3c98c 100644 --- a/README_DEV.md +++ b/README_DEV.md @@ -34,6 +34,6 @@ Rails than you are trying to use now. To run the specs against a different version of Rails, use the `thor` command: ```bash -bin/thor version:use 6.0.2.2 +bin/thor version:use 7.0.3.1 bin/rake ``` diff --git a/example_app_generator/generate_action_mailer_specs.rb b/example_app_generator/generate_action_mailer_specs.rb index b66f052f4..16959ee81 100644 --- a/example_app_generator/generate_action_mailer_specs.rb +++ b/example_app_generator/generate_action_mailer_specs.rb @@ -15,12 +15,7 @@ end CODE - rails_parent = - if Rails.version.to_f >= 6.0 - Rails.application.class.module_parent.to_s - else - Rails.application.class.parent.to_s - end + rails_parent = Rails.application.class.module_parent.to_s gsub_file 'config/initializers/action_mailer.rb', /ExampleApp/, rails_parent diff --git a/example_app_generator/generate_app.rb b/example_app_generator/generate_app.rb index c0d8625c3..13ca7a4c8 100644 --- a/example_app_generator/generate_app.rb +++ b/example_app_generator/generate_app.rb @@ -26,22 +26,12 @@ append_to_file 'Gemfile', "gem 'rails-controller-testing'\n" - if Rails::VERSION::STRING >= '6' - gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'" - - # TODO: To remove when Rails released with https://github.com/rails/rails/pull/40281 - append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '') - |gem 'rexml' - EOT - end + gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'" # sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4` gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'" - # webdrivers 4 up until 4.3.0 don't specify `required_ruby_version`, but contain - # Ruby 2.2-incompatible syntax (safe navigation). - # That basically means we use pre-4.0 for Ruby 2.2, and 4.3+ for newer Rubies. - gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers', '!= 4.0.0', '!= 4.0.1', '!= 4.1.0', '!= 4.1.1', '!= 4.1.2', '!= 4.1.3', '!= 4.2.0'" + gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers'" if RUBY_ENGINE == "jruby" gsub_file "Gemfile", /.*jdbc.*/, '' diff --git a/example_app_generator/spec/support/default_preview_path b/example_app_generator/spec/support/default_preview_path index 5e6bb82cd..64975fe29 100755 --- a/example_app_generator/spec/support/default_preview_path +++ b/example_app_generator/spec/support/default_preview_path @@ -26,11 +26,9 @@ require_file_stub 'config/environment' do require "action_controller/railtie" require "action_mailer/railtie" unless ENV['NO_ACTION_MAILER'] require "action_view/railtie" - if Rails::VERSION::STRING >= '6' - require "action_cable/engine" - require "active_job/railtie" - require "action_mailbox/engine" - end + require "action_cable/engine" + require "active_job/railtie" + require "action_mailbox/engine" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/example_app_generator/spec/verify_custom_renderers_spec.rb b/example_app_generator/spec/verify_custom_renderers_spec.rb index 2edab4b91..f52b03dc9 100644 --- a/example_app_generator/spec/verify_custom_renderers_spec.rb +++ b/example_app_generator/spec/verify_custom_renderers_spec.rb @@ -36,12 +36,6 @@ def index expect(response).to render_template(:bar) end - - it "renders an empty string", skip: Rails::VERSION::STRING.to_f >= 6.0 do - get :index - - expect(response.body).to eq("") - end end context "with a custom renderer prepended to the view path" do diff --git a/features/README.md b/features/README.md index d908df11f..56801b225 100644 --- a/features/README.md +++ b/features/README.md @@ -4,9 +4,10 @@ routing. ## Rails -rspec-rails 5 supports Rails 5.2 to 6.1. For earlier versions of Rails, you -should use [rspec-rails-4](https://github.com/rspec/rspec-rails/tree/4-1-maintenance) -for Rails 5.x and [rspec-rails 3](https://github.com/rspec/rspec-rails/tree/3-9-maintenance) +rspec-rails 6 supports Rails 6.1 to 7.0. For earlier versions of Rails, you +should use [rspec-rails-5](https://github.com/rspec/rspec-rails/tree/5-1-maintenance) +for Rails 5.2 and 6.0, [rspec-rails-4](https://github.com/rspec/rspec-rails/tree/4-1-maintenance) +for Rails 5.x, and [rspec-rails 3](https://github.com/rspec/rspec-rails/tree/3-9-maintenance) for even older versions. ## Install @@ -26,7 +27,7 @@ This installs the following gems: Add rspec-rails to the :test and :development groups in the Gemfile: group :test, :development do - gem 'rspec-rails', '~> 5.0.0' + gem 'rspec-rails', '~> 6.0.0' end It needs to be in the :development group to expose generators and rake tasks diff --git a/features/channel_specs/channel_spec.feature b/features/channel_specs/channel_spec.feature index 3c48fdd7b..314ab936e 100644 --- a/features/channel_specs/channel_spec.feature +++ b/features/channel_specs/channel_spec.feature @@ -1,4 +1,3 @@ -@rails_post_6 Feature: channel spec Channel specs are marked by `:type => :channel` or if you have set diff --git a/features/controller_specs/anonymous_controller.feature b/features/controller_specs/anonymous_controller.feature index 9baf73fb8..fa2c99e6c 100644 --- a/features/controller_specs/anonymous_controller.feature +++ b/features/controller_specs/anonymous_controller.feature @@ -101,43 +101,6 @@ Feature: anonymous controller When I run `rspec spec` Then the examples should all pass - # Deprecated support removed in https://github.com/rails/rails/commit/d52d7739468153bd6cb7c629f60bd5cd7ebea3eb - @rails_pre_6 - Scenario: Specify error handling in `ApplicationController` with render :file - Given a file named "spec/controllers/application_controller_spec.rb" with: - """ruby - require "rails_helper" - - class ApplicationController < ActionController::Base - class AccessDenied < StandardError; end - - rescue_from AccessDenied, :with => :access_denied - - private - - def access_denied - render :file => "errors/401" - end - end - - RSpec.describe ApplicationController, :type => :controller do - controller do - def index - raise ApplicationController::AccessDenied - end - end - - describe "handling AccessDenied exceptions" do - it "renders the errors/401 template" do - get :index - expect(response).to render_template("errors/401") - end - end - end - """ - When I run `rspec spec` - Then the examples should all pass - Scenario: Specify error handling in a subclass Given a file named "spec/controllers/application_controller_subclass_spec.rb" with: """ruby diff --git a/features/controller_specs/controller_spec.feature b/features/controller_specs/controller_spec.feature index 6ce5706be..d6caf8409 100644 --- a/features/controller_specs/controller_spec.feature +++ b/features/controller_specs/controller_spec.feature @@ -34,30 +34,6 @@ Feature: controller spec When I run `rspec spec` Then the example should pass - @rails_pre_6 - Scenario: setting a different content type for example json (request type) - Given a file named "spec/controllers/widgets_controller_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe WidgetsController, :type => :controller do - describe "responds to" do - it "responds to html by default" do - post :create, :params => { :widget => { :name => "Any Name" } } - expect(response.content_type).to eq "text/html" - end - - it "responds to custom formats when provided in the params" do - post :create, :params => { :widget => { :name => "Any Name" }, :format => :json } - expect(response.content_type).to eq "application/json" - end - end - end - """ - When I run `rspec spec` - Then the example should pass - - @rails_post_6 Scenario: setting a different content type for example json (request type) Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby @@ -80,7 +56,6 @@ Feature: controller spec When I run `rspec spec` Then the example should pass - @rails_post_6 Scenario: setting a different media type for example json (request type) Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby diff --git a/features/mailbox_specs/mailbox_spec.feature b/features/mailbox_specs/mailbox_spec.feature index e1a9a6234..1a9423f91 100644 --- a/features/mailbox_specs/mailbox_spec.feature +++ b/features/mailbox_specs/mailbox_spec.feature @@ -1,4 +1,3 @@ -@rails_post_6 Feature: action mailbox spec Mailbox specs provide alternative assertions to those available in `ActiveMailbox::TestHelper` and help assert behaviour of how the email diff --git a/features/matchers/have_broadcasted_matcher.feature b/features/matchers/have_broadcasted_matcher.feature index 1c0dc2577..40f8537ae 100644 --- a/features/matchers/have_broadcasted_matcher.feature +++ b/features/matchers/have_broadcasted_matcher.feature @@ -1,4 +1,3 @@ -@rails_post_6 Feature: have_broadcasted matcher The `have_broadcasted_to` (also aliased as `broadcast_to`) matcher is used diff --git a/features/matchers/have_enqueued_mail_matcher.feature b/features/matchers/have_enqueued_mail_matcher.feature index dda6b46f9..3ad05399a 100644 --- a/features/matchers/have_enqueued_mail_matcher.feature +++ b/features/matchers/have_enqueued_mail_matcher.feature @@ -68,7 +68,6 @@ Feature: have_enqueued_mail matcher When I run `rspec spec/mailers/my_mailer_spec.rb` Then the examples should all pass - @rails_post_6 Scenario: Parameterize the mailer Given a file named "app/mailers/my_mailer.rb" with: """ruby @@ -98,7 +97,6 @@ Feature: have_enqueued_mail matcher When I run `rspec spec/mailers/my_mailer_spec.rb` Then the examples should all pass - @rails_post_6 Scenario: Parameterize and pass an argument to the mailer Given a file named "app/mailers/my_mailer.rb" with: """ruby diff --git a/features/matchers/have_stream_from_matcher.feature b/features/matchers/have_stream_from_matcher.feature index 01f2a5f36..156b4043d 100644 --- a/features/matchers/have_stream_from_matcher.feature +++ b/features/matchers/have_stream_from_matcher.feature @@ -1,4 +1,3 @@ -@rails_post_6 Feature: have_stream_from matcher The `have_stream_from` matcher is used to check if a channel has been subscribed to a given stream specified as a String. diff --git a/features/request_specs/request_spec.feature b/features/request_specs/request_spec.feature index aa312c8f1..31d21821c 100644 --- a/features/request_specs/request_spec.feature +++ b/features/request_specs/request_spec.feature @@ -55,28 +55,6 @@ Feature: request spec When I run `rspec spec/requests/widget_management_spec.rb` Then the example should pass - @rails_pre_6 - Scenario: requesting a JSON response - Given a file named "spec/requests/widget_management_spec.rb" with: - """ruby - require "rails_helper" - - RSpec.describe "Widget management", :type => :request do - - it "creates a Widget" do - headers = { "ACCEPT" => "application/json" } - post "/widgets", :params => { :widget => {:name => "My Widget"} }, :headers => headers - - expect(response.content_type).to eq("application/json") - expect(response).to have_http_status(:created) - end - - end - """ - When I run `rspec spec/requests/widget_management_spec.rb` - Then the example should pass - - @rails_post_6 Scenario: requesting a JSON response Given a file named "spec/requests/widget_management_spec.rb" with: """ruby diff --git a/features/support/rails_versions.rb b/features/support/rails_versions.rb deleted file mode 100644 index 38d8b6f8c..000000000 --- a/features/support/rails_versions.rb +++ /dev/null @@ -1,22 +0,0 @@ -def rails_version - string_version = ENV.fetch("RAILS_VERSION", "~> 6.0.0") - if string_version == "main" || string_version.nil? - Float::INFINITY - else - string_version[/\d[\.-]\d/].tr('-', '.') - end -end - -Before "@rails_pre_6" do |scenario| - if rails_version.to_f >= 6.0 - warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}" - skip_this_scenario - end -end - -Before "@rails_post_6" do |scenario| - if rails_version.to_f < 6.0 - warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}" - skip_this_scenario - end -end diff --git a/features/upgrade/README.md b/features/upgrade/README.md index 029861fdd..5b91c9fcc 100644 --- a/features/upgrade/README.md +++ b/features/upgrade/README.md @@ -1,3 +1,9 @@ +# Upgrading from rspec-rails 5.x to version 6 + +RSpec Rails 6 is a major version under semantic versioning, it also follows our new versioning strategy for RSpec-Rails, which is to keep in step with Rails supported versions. Thus it supports 6.1 and 7.0. There are no changes required to upgrade to RSpec Rails 6 if you are using a supported version of Rails. + +If you are using an older version of Rails, you can use 5.x which hard supports 5.2 and 6.x. + # Upgrading from rspec-rails 4.x to version 5 RSpec Rails 5 is a major version under semantic versioning, it also follows our new versioning strategy for RSpec-Rails, which is to keep in step with Rails supported versions. Thus it supports 5.2, 6.0 and 6.1. There are no changes required to upgrade to RSpec Rails 5 if you are using a supported version of Rails. diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index 361c777df..45592fbd8 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -8,11 +8,7 @@ module Rails class Railtie < ::Rails::Railtie # As of Rails 5.1.0 you can register directories to work with `rake notes` require 'rails/source_annotation_extractor' - if ::Rails::VERSION::STRING >= '6.0' - ::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec") - else - SourceAnnotationExtractor::Annotation.register_directories("spec") - end + ::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec") generators = config.app_generators generators.integration_tool :rspec generators.test_framework :rspec diff --git a/lib/rspec/rails/example/system_example_group.rb b/lib/rspec/rails/example/system_example_group.rb index 046da3ebe..8e0bb5ffe 100644 --- a/lib/rspec/rails/example/system_example_group.rb +++ b/lib/rspec/rails/example/system_example_group.rb @@ -54,23 +54,22 @@ def app ActionDispatch::SystemTesting::Server.silence_puma = true end + require 'action_dispatch/system_test_case' + begin require 'capybara' - require 'action_dispatch/system_test_case' rescue LoadError => e abort """ LoadError: #{e.message} - System test integration requires Rails >= 5.1 and has a hard + System test integration has a hard dependency on a webserver and `capybara`, please add capybara to your Gemfile and configure a webserver (e.g. `Capybara.server = - :webrick`) before attempting to use system specs. + :puma`) before attempting to use system specs. """.gsub(/\s+/, ' ').strip end - if ::Rails::VERSION::STRING >= '6.0' - original_before_teardown = - ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown) - end + original_before_teardown = + ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown) original_after_teardown = ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown) diff --git a/lib/rspec/rails/feature_check.rb b/lib/rspec/rails/feature_check.rb index 4a4d855d7..a19b2cfef 100644 --- a/lib/rspec/rails/feature_check.rb +++ b/lib/rspec/rails/feature_check.rb @@ -24,7 +24,7 @@ def has_action_mailer_preview? end def has_action_cable_testing? - defined?(::ActionCable) && ActionCable::VERSION::MAJOR >= 6 + defined?(::ActionCable) end def has_action_mailer_parameterized? diff --git a/lib/rspec/rails/fixture_file_upload_support.rb b/lib/rspec/rails/fixture_file_upload_support.rb index ef4989c65..c32172850 100644 --- a/lib/rspec/rails/fixture_file_upload_support.rb +++ b/lib/rspec/rails/fixture_file_upload_support.rb @@ -6,41 +6,24 @@ module FixtureFileUploadSupport private - # In Rails 6.2 fixture file path needs to be relative to `file_fixture_path` instead, this change - # was brought in with a deprecation warning on 6.1. In Rails 6.2 expect to rework this to remove + # In Rails 7.0 fixture file path needs to be relative to `file_fixture_path` instead, this change + # was brought in with a deprecation warning on 6.1. In Rails 7.0 expect to rework this to remove # the old accessor. - if ::Rails.version.to_f >= 6.1 - def rails_fixture_file_wrapper - RailsFixtureFileWrapper.file_fixture_path = nil - resolved_fixture_path = - if respond_to?(:file_fixture_path) && !file_fixture_path.nil? - file_fixture_path.to_s - else - (RSpec.configuration.fixture_path || '').to_s - end - RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty? - RailsFixtureFileWrapper.instance - end - else - def rails_fixture_file_wrapper - RailsFixtureFileWrapper.fixture_path = nil - resolved_fixture_path = - if respond_to?(:fixture_path) && !fixture_path.nil? - fixture_path.to_s - else - (RSpec.configuration.fixture_path || '').to_s - end - RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty? - RailsFixtureFileWrapper.instance - end + def rails_fixture_file_wrapper + RailsFixtureFileWrapper.file_fixture_path = nil + resolved_fixture_path = + if respond_to?(:file_fixture_path) && !file_fixture_path.nil? + file_fixture_path.to_s + else + (RSpec.configuration.fixture_path || '').to_s + end + RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty? + RailsFixtureFileWrapper.instance end class RailsFixtureFileWrapper include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess) - - if ::Rails.version.to_f >= 6.1 - include ActiveSupport::Testing::FileFixtures - end + include ActiveSupport::Testing::FileFixtures class << self attr_accessor :fixture_path diff --git a/lib/rspec/rails/vendor/capybara.rb b/lib/rspec/rails/vendor/capybara.rb index c6c735869..97f8eb64e 100644 --- a/lib/rspec/rails/vendor/capybara.rb +++ b/lib/rspec/rails/vendor/capybara.rb @@ -12,9 +12,7 @@ RSpec.configure do |c| if defined?(Capybara::DSL) c.include Capybara::DSL, type: :feature - if defined?(ActionPack) && ActionPack::VERSION::STRING >= "5.1" - c.include Capybara::DSL, type: :system - end + c.include Capybara::DSL, type: :system end if defined?(Capybara::RSpecMatchers) diff --git a/lib/rspec/rails/view_assigns.rb b/lib/rspec/rails/view_assigns.rb index e8bbb5fa7..2b9d05fa0 100644 --- a/lib/rspec/rails/view_assigns.rb +++ b/lib/rspec/rails/view_assigns.rb @@ -13,26 +13,8 @@ def assign(key, value) end # Compat-shim for AbstractController::Rendering#view_assigns - # - # _assigns was deprecated in favor of view_assigns after - # Rails-3.0.0 was released. Since we are not able to predict when - # the _assigns/view_assigns patch will be released (I thought it - # would have been in 3.0.1, but 3.0.1 bypassed this change for a - # security fix), this bit ensures that we do the right thing without - # knowing anything about the Rails version we are dealing with. - # - # Once that change _is_ released, this can be changed to something - # that checks for the Rails version when the module is being - # interpreted, as it was before commit dd0095. def view_assigns super.merge(_encapsulated_assigns) - rescue - _assigns - end - - # @private - def _assigns - super.merge(_encapsulated_assigns) end private diff --git a/lib/rspec/rails/view_rendering.rb b/lib/rspec/rails/view_rendering.rb index 22eff75ba..9ad81c50c 100644 --- a/lib/rspec/rails/view_rendering.rb +++ b/lib/rspec/rails/view_rendering.rb @@ -62,14 +62,8 @@ def self.nullify_template_rendering(templates) end end - if ::Rails::VERSION::STRING >= '6' - def self.template_format(template) - template.format - end - else - def self.template_format(template) - template.formats - end + def self.template_format(template) + template.format end # Delegates all methods to the submitted resolver and for all methods diff --git a/spec/rspec/rails/fixture_file_upload_support_spec.rb b/spec/rspec/rails/fixture_file_upload_support_spec.rb index af074704d..3c5c0bda7 100644 --- a/spec/rspec/rails/fixture_file_upload_support_spec.rb +++ b/spec/rspec/rails/fixture_file_upload_support_spec.rb @@ -35,11 +35,7 @@ def fixture_file_upload_resolved(fixture_name, fixture_path = nil) RSpec::Core::ExampleGroup.describe do include RSpec::Rails::FixtureFileUploadSupport - if ::Rails.version.to_f >= 6.1 - self.file_fixture_path = fixture_path - else - self.fixture_path = fixture_path - end + self.file_fixture_path = fixture_path it 'supports fixture file upload' do file = fixture_file_upload(fixture_name) diff --git a/spec/rspec/rails/fixture_support_spec.rb b/spec/rspec/rails/fixture_support_spec.rb index 62b08a303..534a06312 100644 --- a/spec/rspec/rails/fixture_support_spec.rb +++ b/spec/rspec/rails/fixture_support_spec.rb @@ -39,7 +39,7 @@ def expect_to_pass(group) end end - it "will allow #setup_fixture to run successfully", skip: Rails.version.to_f <= 6.0 do + it "will allow #setup_fixture to run successfully" do group = RSpec::Core::ExampleGroup.describe do include FixtureSupport diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index d4c8e2ea9..70635ec38 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -379,22 +379,20 @@ def self.name; "LoggingJob"; end } end - if Rails.version.to_f >= 6.0 - it "passes with Time" do - usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z') + it "passes with Time" do + usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z') - expect { - hello_job.perform_later(usec_time) - }.to have_enqueued_job(hello_job).with(usec_time) - end + expect { + hello_job.perform_later(usec_time) + }.to have_enqueued_job(hello_job).with(usec_time) + end - it "passes with ActiveSupport::TimeWithZone" do - usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z').in_time_zone + it "passes with ActiveSupport::TimeWithZone" do + usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z').in_time_zone - expect { - hello_job.perform_later(usec_time) - }.to have_enqueued_job(hello_job).with(usec_time) - end + expect { + hello_job.perform_later(usec_time) + }.to have_enqueued_job(hello_job).with(usec_time) end end From 880a2d573aa5a71721d52094c61db39393d17b10 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Mon, 18 Jul 2022 00:37:50 +0300 Subject: [PATCH 5/5] Remove legacy --- features/support/rubinius.rb | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 features/support/rubinius.rb diff --git a/features/support/rubinius.rb b/features/support/rubinius.rb deleted file mode 100644 index b09d67abb..000000000 --- a/features/support/rubinius.rb +++ /dev/null @@ -1,6 +0,0 @@ -# Required until https://github.com/rubinius/rubinius/issues/2430 is resolved -ENV['RBXOPT'] = "#{ENV['RBXOPT']} -Xcompiler.no_rbc" - -Around "@unsupported-on-rbx" do |_scenario, block| - block.call unless defined?(Rubinius) -end