Skip to content

Remove version-specific checks for unsupported Rails/Ruby #2614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,12 @@ 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)

eval_gemfile 'Gemfile-sqlite-dependencies'
eval_gemfile 'Gemfile-rails-dependencies'
3 changes: 3 additions & 0 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 0 additions & 20 deletions Gemfile-sqlite-dependencies

This file was deleted.

2 changes: 1 addition & 1 deletion README_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
6 changes: 3 additions & 3 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions example_app_generator/config/initializers/sqlite3_fix.rb

This file was deleted.

7 changes: 1 addition & 6 deletions example_app_generator/generate_action_mailer_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 4 additions & 24 deletions example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand All @@ -27,31 +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'"
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

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
gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers'"

if RUBY_ENGINE == "jruby"
gsub_file "Gemfile", /.*jdbc.*/, ''
Expand Down
8 changes: 3 additions & 5 deletions example_app_generator/spec/support/default_preview_path
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions example_app_generator/spec/verify_custom_renderers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion features/channel_specs/channel_spec.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@rails_post_6
Feature: channel spec

Channel specs are marked by `:type => :channel` or if you have set
Expand Down
37 changes: 0 additions & 37 deletions features/controller_specs/anonymous_controller.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions features/controller_specs/controller_spec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion features/mailbox_specs/mailbox_spec.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion features/matchers/have_broadcasted_matcher.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@rails_post_6
Feature: have_broadcasted matcher

The `have_broadcasted_to` (also aliased as `broadcast_to`) matcher is used
Expand Down
2 changes: 0 additions & 2 deletions features/matchers/have_enqueued_mail_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion features/matchers/have_stream_from_matcher.feature
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
22 changes: 0 additions & 22 deletions features/request_specs/request_spec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions features/support/rails_versions.rb

This file was deleted.

6 changes: 0 additions & 6 deletions features/support/rubinius.rb

This file was deleted.

6 changes: 6 additions & 0 deletions features/upgrade/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 1 addition & 5 deletions lib/rspec-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading