Skip to content

Commit 8f449ab

Browse files
authored
Merge pull request #2614 from rspec/remove-some-hacks
Remove version-specific checks for unsupported Rails/Ruby
2 parents 7b7a86f + 880a2d5 commit 8f449ab

35 files changed

+67
-297
lines changed

Gemfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,12 @@ group :documentation do
1212
gem 'relish', '~> 0.7.1'
1313
end
1414

15-
gem 'rake', '> 12'
16-
17-
if RUBY_VERSION.to_f >= 2.3
18-
gem 'rubocop', '~> 0.80.1'
19-
end
20-
2115
gem 'capybara'
22-
23-
if RUBY_VERSION.to_f >= 2.3
24-
gem 'ffi', '~> 1.15.5'
25-
else
26-
gem 'ffi', '~> 1.12.0'
27-
end
16+
gem 'ffi', '~> 1.15.5'
17+
gem 'rake', '> 12'
18+
gem 'rubocop', '~> 0.80.1'
2819

2920
custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
3021
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)
3122

32-
eval_gemfile 'Gemfile-sqlite-dependencies'
3323
eval_gemfile 'Gemfile-rails-dependencies'

Gemfile-rails-dependencies

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def add_net_gems_dependency
1111
end
1212
end
1313

14+
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
15+
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
16+
1417
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
1518
when /main/
1619
gem "rails", :git => "https://github.com/rails/rails.git"

Gemfile-sqlite-dependencies

Lines changed: 0 additions & 20 deletions
This file was deleted.

README_DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ Rails than you are trying to use now.
3434
To run the specs against a different version of Rails, use the `thor` command:
3535

3636
```bash
37-
bin/thor version:use 6.0.2.2
37+
bin/thor version:use 7.0.3.1
3838
bin/rake
3939
```

cucumber.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
default: --require features --format progress --tags 'not @wip'
2-
pretty: --require features --format pretty --tags 'not @wip'
3-
wip: --require features --tags @wip
1+
default: --publish-quiet --require features --format progress --tags 'not @wip'
2+
pretty: --publish-quiet --require features --format pretty --tags 'not @wip'
3+
wip: --publish-quiet --require features --tags @wip

example_app_generator/config/initializers/sqlite3_fix.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

example_app_generator/generate_action_mailer_specs.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
end
1616
CODE
1717

18-
rails_parent =
19-
if Rails.version.to_f >= 6.0
20-
Rails.application.class.module_parent.to_s
21-
else
22-
Rails.application.class.parent.to_s
23-
end
18+
rails_parent = Rails.application.class.module_parent.to_s
2419

2520
gsub_file 'config/initializers/action_mailer.rb', /ExampleApp/, rails_parent
2621

example_app_generator/generate_app.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'ci_retry_bundle_install.sh'
1212
)
1313
function_script_file = File.join(rspec_rails_repo_path, 'script/functions.sh')
14-
sqlite_initializer = File.join(rspec_rails_repo_path, "example_app_generator/config/initializers/sqlite3_fix.rb")
1514

1615
in_root do
1716
prepend_to_file "Rakefile", "require 'active_support/all'"
@@ -27,31 +26,12 @@
2726

2827
append_to_file 'Gemfile', "gem 'rails-controller-testing'\n"
2928

30-
if Rails::VERSION::STRING >= '6'
31-
gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'"
29+
gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'"
3230

33-
# TODO: To remove when Rails released with https://github.com/rails/rails/pull/40281
34-
append_to_file 'Gemfile', <<-EOT.gsub(/^ +\|/, '')
35-
|gem 'rexml'
36-
EOT
37-
end
38-
39-
if Rails::VERSION::STRING >= '6'
40-
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
41-
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'"
42-
else
43-
# Similarly, Rails 5.0 only supports '~> 1.3.6'. Rails 5.1-5.2 support '~> 1.3', '>= 1.3.6'
44-
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'"
45-
end
31+
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
32+
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'"
4633

47-
# webdrivers 4 up until 4.3.0 don't specify `required_ruby_version`, but contain
48-
# Ruby 2.2-incompatible syntax (safe navigation).
49-
# That basically means we use pre-4.0 for Ruby 2.2, and 4.3+ for newer Rubies.
50-
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'"
51-
52-
if Rails::VERSION::STRING < '6'
53-
copy_file sqlite_initializer, 'config/initializers/sqlite3_fix.rb'
54-
end
34+
gsub_file "Gemfile", /.*chromedriver-helper.*/, "gem 'webdrivers'"
5535

5636
if RUBY_ENGINE == "jruby"
5737
gsub_file "Gemfile", /.*jdbc.*/, ''

example_app_generator/spec/support/default_preview_path

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ require_file_stub 'config/environment' do
2626
require "action_controller/railtie"
2727
require "action_mailer/railtie" unless ENV['NO_ACTION_MAILER']
2828
require "action_view/railtie"
29-
if Rails::VERSION::STRING >= '6'
30-
require "action_cable/engine"
31-
require "active_job/railtie"
32-
require "action_mailbox/engine"
33-
end
29+
require "action_cable/engine"
30+
require "active_job/railtie"
31+
require "action_mailbox/engine"
3432

3533
# Require the gems listed in Gemfile, including any gems
3634
# you've limited to :test, :development, or :production.

example_app_generator/spec/verify_custom_renderers_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ def index
3636

3737
expect(response).to render_template(:bar)
3838
end
39-
40-
it "renders an empty string", skip: Rails::VERSION::STRING.to_f >= 6.0 do
41-
get :index
42-
43-
expect(response.body).to eq("")
44-
end
4539
end
4640

4741
context "with a custom renderer prepended to the view path" do

features/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ routing.
44

55
## Rails
66

7-
rspec-rails 5 supports Rails 5.2 to 6.1. For earlier versions of Rails, you
8-
should use [rspec-rails-4](https://github.com/rspec/rspec-rails/tree/4-1-maintenance)
9-
for Rails 5.x and [rspec-rails 3](https://github.com/rspec/rspec-rails/tree/3-9-maintenance)
7+
rspec-rails 6 supports Rails 6.1 to 7.0. For earlier versions of Rails, you
8+
should use [rspec-rails-5](https://github.com/rspec/rspec-rails/tree/5-1-maintenance)
9+
for Rails 5.2 and 6.0, [rspec-rails-4](https://github.com/rspec/rspec-rails/tree/4-1-maintenance)
10+
for Rails 5.x, and [rspec-rails 3](https://github.com/rspec/rspec-rails/tree/3-9-maintenance)
1011
for even older versions.
1112

1213
## Install
@@ -26,7 +27,7 @@ This installs the following gems:
2627
Add rspec-rails to the :test and :development groups in the Gemfile:
2728

2829
group :test, :development do
29-
gem 'rspec-rails', '~> 5.0.0'
30+
gem 'rspec-rails', '~> 6.0.0'
3031
end
3132

3233
It needs to be in the :development group to expose generators and rake tasks

features/channel_specs/channel_spec.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@rails_post_6
21
Feature: channel spec
32

43
Channel specs are marked by `:type => :channel` or if you have set

features/controller_specs/anonymous_controller.feature

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,43 +101,6 @@ Feature: anonymous controller
101101
When I run `rspec spec`
102102
Then the examples should all pass
103103

104-
# Deprecated support removed in https://github.com/rails/rails/commit/d52d7739468153bd6cb7c629f60bd5cd7ebea3eb
105-
@rails_pre_6
106-
Scenario: Specify error handling in `ApplicationController` with render :file
107-
Given a file named "spec/controllers/application_controller_spec.rb" with:
108-
"""ruby
109-
require "rails_helper"
110-
111-
class ApplicationController < ActionController::Base
112-
class AccessDenied < StandardError; end
113-
114-
rescue_from AccessDenied, :with => :access_denied
115-
116-
private
117-
118-
def access_denied
119-
render :file => "errors/401"
120-
end
121-
end
122-
123-
RSpec.describe ApplicationController, :type => :controller do
124-
controller do
125-
def index
126-
raise ApplicationController::AccessDenied
127-
end
128-
end
129-
130-
describe "handling AccessDenied exceptions" do
131-
it "renders the errors/401 template" do
132-
get :index
133-
expect(response).to render_template("errors/401")
134-
end
135-
end
136-
end
137-
"""
138-
When I run `rspec spec`
139-
Then the examples should all pass
140-
141104
Scenario: Specify error handling in a subclass
142105
Given a file named "spec/controllers/application_controller_subclass_spec.rb" with:
143106
"""ruby

features/controller_specs/controller_spec.feature

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,6 @@ Feature: controller spec
3434
When I run `rspec spec`
3535
Then the example should pass
3636

37-
@rails_pre_6
38-
Scenario: setting a different content type for example json (request type)
39-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
40-
"""ruby
41-
require "rails_helper"
42-
43-
RSpec.describe WidgetsController, :type => :controller do
44-
describe "responds to" do
45-
it "responds to html by default" do
46-
post :create, :params => { :widget => { :name => "Any Name" } }
47-
expect(response.content_type).to eq "text/html"
48-
end
49-
50-
it "responds to custom formats when provided in the params" do
51-
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
52-
expect(response.content_type).to eq "application/json"
53-
end
54-
end
55-
end
56-
"""
57-
When I run `rspec spec`
58-
Then the example should pass
59-
60-
@rails_post_6
6137
Scenario: setting a different content type for example json (request type)
6238
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
6339
"""ruby
@@ -80,7 +56,6 @@ Feature: controller spec
8056
When I run `rspec spec`
8157
Then the example should pass
8258

83-
@rails_post_6
8459
Scenario: setting a different media type for example json (request type)
8560
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
8661
"""ruby

features/mailbox_specs/mailbox_spec.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@rails_post_6
21
Feature: action mailbox spec
32

43
Mailbox specs provide alternative assertions to those available in `ActiveMailbox::TestHelper` and help assert behaviour of how the email

features/matchers/have_broadcasted_matcher.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@rails_post_6
21
Feature: have_broadcasted matcher
32

43
The `have_broadcasted_to` (also aliased as `broadcast_to`) matcher is used

features/matchers/have_enqueued_mail_matcher.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Feature: have_enqueued_mail matcher
6868
When I run `rspec spec/mailers/my_mailer_spec.rb`
6969
Then the examples should all pass
7070

71-
@rails_post_6
7271
Scenario: Parameterize the mailer
7372
Given a file named "app/mailers/my_mailer.rb" with:
7473
"""ruby
@@ -98,7 +97,6 @@ Feature: have_enqueued_mail matcher
9897
When I run `rspec spec/mailers/my_mailer_spec.rb`
9998
Then the examples should all pass
10099

101-
@rails_post_6
102100
Scenario: Parameterize and pass an argument to the mailer
103101
Given a file named "app/mailers/my_mailer.rb" with:
104102
"""ruby

features/matchers/have_stream_from_matcher.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@rails_post_6
21
Feature: have_stream_from matcher
32

43
The `have_stream_from` matcher is used to check if a channel has been subscribed to a given stream specified as a String.

features/request_specs/request_spec.feature

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,6 @@ Feature: request spec
5555
When I run `rspec spec/requests/widget_management_spec.rb`
5656
Then the example should pass
5757

58-
@rails_pre_6
59-
Scenario: requesting a JSON response
60-
Given a file named "spec/requests/widget_management_spec.rb" with:
61-
"""ruby
62-
require "rails_helper"
63-
64-
RSpec.describe "Widget management", :type => :request do
65-
66-
it "creates a Widget" do
67-
headers = { "ACCEPT" => "application/json" }
68-
post "/widgets", :params => { :widget => {:name => "My Widget"} }, :headers => headers
69-
70-
expect(response.content_type).to eq("application/json")
71-
expect(response).to have_http_status(:created)
72-
end
73-
74-
end
75-
"""
76-
When I run `rspec spec/requests/widget_management_spec.rb`
77-
Then the example should pass
78-
79-
@rails_post_6
8058
Scenario: requesting a JSON response
8159
Given a file named "spec/requests/widget_management_spec.rb" with:
8260
"""ruby

features/support/rails_versions.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

features/support/rubinius.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

features/upgrade/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Upgrading from rspec-rails 5.x to version 6
2+
3+
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.
4+
5+
If you are using an older version of Rails, you can use 5.x which hard supports 5.2 and 6.x.
6+
17
# Upgrading from rspec-rails 4.x to version 5
28

39
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.

lib/rspec-rails.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ module Rails
88
class Railtie < ::Rails::Railtie
99
# As of Rails 5.1.0 you can register directories to work with `rake notes`
1010
require 'rails/source_annotation_extractor'
11-
if ::Rails::VERSION::STRING >= '6.0'
12-
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
13-
else
14-
SourceAnnotationExtractor::Annotation.register_directories("spec")
15-
end
11+
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
1612
generators = config.app_generators
1713
generators.integration_tool :rspec
1814
generators.test_framework :rspec

0 commit comments

Comments
 (0)