Skip to content

Commit f249b48

Browse files
authored
Merge pull request #2476 from rspec/prep-version-5
Prep version 5
2 parents b694a75 + 1543e02 commit f249b48

File tree

22 files changed

+153
-312
lines changed

22 files changed

+153
-312
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,6 @@ jobs:
7474
- ruby: 2.2.10
7575
env:
7676
RAILS_VERSION: '5-2-stable'
77-
# Rails 5.1 Builds >= 2.2.2
78-
- ruby: 2.6.6
79-
env:
80-
RAILS_VERSION: '~> 5.1.0'
81-
- ruby: 2.5.8
82-
env:
83-
RAILS_VERSION: '~> 5.1.0'
84-
- ruby: 2.4.10
85-
env:
86-
RAILS_VERSION: '~> 5.1.0'
87-
- ruby: 2.3.8
88-
env:
89-
RAILS_VERSION: '~> 5.1.0'
90-
- ruby: 2.2.10
91-
env:
92-
RAILS_VERSION: '~> 5.1.0'
93-
# Rails 5.0 Builds >= 2.2.2
94-
- ruby: 2.6.6
95-
env:
96-
RAILS_VERSION: '~> 5.0.0'
97-
- ruby: 2.5.8
98-
env:
99-
RAILS_VERSION: '~> 5.0.0'
100-
- ruby: 2.4.10
101-
env:
102-
RAILS_VERSION: '~> 5.0.0'
103-
- ruby: 2.3.8
104-
env:
105-
RAILS_VERSION: '~> 5.0.0'
106-
- ruby: 2.2.10
107-
env:
108-
RAILS_VERSION: '~> 5.0.0'
10977
env: ${{ matrix.env }}
11078
steps:
11179
- uses: actions/checkout@v2

Changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
### Development
1+
### 5.0.0
22
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.0...main)
33

4+
Enhancements:
5+
46
* Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)
57
* Support for Rails 6.1. (Benoit Tigeot, Jon Rowe, Phil Pirozhkov, and more #2398)
68

9+
Breaking Changes:
10+
11+
* Drop support for Rails below 5.2.
12+
713
### 4.1.0 / 2021-03-06
814

915
Enhancements:

Gemfile-rails-dependencies

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ when /master/
1717
gem 'selenium-webdriver', require: false
1818
when /stable$/
1919
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport activejob actionview]
20-
gem 'puma', "3.12.1" if version > '5-0-stable'
20+
gem 'puma', "3.12.1"
2121
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]
2222

2323
gem_list.each do |rails_gem|
@@ -31,7 +31,7 @@ when nil, false, ""
3131
else
3232
gem "rails", version
3333
gem "sprockets", '~> 3.0' if RUBY_VERSION < '2.5'
34-
gem "puma" if version >= '5-1-stable'
34+
gem "puma"
3535
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
36-
gem 'selenium-webdriver', require: false if version >= '5'
36+
gem 'selenium-webdriver', require: false
3737
end

Rakefile

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ require 'cucumber/rake/task'
1313

1414
def rails_template_command
1515
require "rails/version"
16-
if Rails.version.to_f >= 5.0
17-
"app:template"
18-
else
19-
"rails:template"
20-
end
16+
"app:template"
2117
end
2218

2319
desc "Run all examples"
@@ -36,14 +32,6 @@ Cucumber::Rake::Task.new(:cucumber) do |t|
3632
end
3733
tags = []
3834

39-
if version.to_f >= 5.1
40-
tags << "~@rails_pre_5.1"
41-
end
42-
43-
if version.to_f == 5.0
44-
tags << "~@system_test"
45-
end
46-
4735
if version.to_f >= 6.0
4836
tags << "~@rails_pre_6"
4937
end

example_app_generator/generate_app.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
gsub_file "Gemfile", /.*puma.*/, ''
2525
gsub_file "Gemfile", /.*bootsnap.*/, ''
2626

27-
# We soft-support Rails 4.2. `rails-controller-testing` only supports Rails 5+.
28-
# This conditional is to facilitate local testing against Rails 4.2.
29-
if Rails::VERSION::STRING >= '5'
30-
append_to_file 'Gemfile', "gem 'rails-controller-testing'\n"
31-
end
27+
append_to_file 'Gemfile', "gem 'rails-controller-testing'\n"
3228

3329
if Rails::VERSION::STRING >= '6'
3430
gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'"
@@ -47,14 +43,12 @@
4743
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'"
4844
end
4945

50-
if Rails::VERSION::STRING >= "5.1.0"
51-
# webdrivers 4 up until 4.3.0 don't specify `required_ruby_version`, but contain
52-
# Ruby 2.2-incompatible syntax (safe navigation).
53-
# That basically means we use pre-4.0 for Ruby 2.2, and 4.3+ for newer Rubies.
54-
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'"
55-
end
46+
# webdrivers 4 up until 4.3.0 don't specify `required_ruby_version`, but contain
47+
# Ruby 2.2-incompatible syntax (safe navigation).
48+
# That basically means we use pre-4.0 for Ruby 2.2, and 4.3+ for newer Rubies.
49+
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'"
5650

57-
if Rails::VERSION::STRING >= '5.2.0' && Rails::VERSION::STRING < '6'
51+
if Rails::VERSION::STRING < '6'
5852
copy_file sqlite_initializer, 'config/initializers/sqlite3_fix.rb'
5953
end
6054

features/feature_specs/feature_spec.feature

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,6 @@ Feature: Feature spec
1717
[customer](http://c2.com/cgi/wiki?CustomerTest) and [acceptance](http://c2.com/cgi/wiki?AcceptanceTest) tests. When capybara is required it sets
1818
`:type => :feature` automatically for you.
1919

20-
@rails_pre_5.1
21-
Scenario: Feature specs are skipped without Capybara
22-
Given a file named "spec/features/widget_management_spec.rb" with:
23-
"""ruby
24-
require "rails_helper"
25-
26-
RSpec.feature "Widget management", :type => :feature do
27-
scenario "User creates a new widget" do
28-
visit "/widgets/new"
29-
30-
fill_in "Name", :with => "My Widget"
31-
click_button "Create Widget"
32-
33-
expect(page).to have_text("Widget was successfully created.")
34-
end
35-
end
36-
"""
37-
When I run `rspec spec/features/widget_management_spec.rb`
38-
Then the exit status should be 0
39-
And the output should contain "1 example, 0 failures, 1 pending"
40-
And the output should contain:
41-
"""
42-
Pending: (Failures listed here are expected and do not affect your suite's status)
43-
44-
1) Widget management User creates a new widget
45-
# Feature specs require the Capybara (https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later.
46-
# ./spec/features/widget_management_spec.rb:4
47-
"""
48-
4920
@capybara
5021
Scenario: specify creating a Widget by driving the application with capybara
5122
Given a file named "spec/features/widget_management_spec.rb" with:

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 4.x to version 5
2+
3+
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.
4+
5+
If you are using an older version of Rails, you can use 4.x which hard supports 5.0 and 5.1, and soft supports 4.2 (which is unmaintained).
6+
17
# Upgrading from rspec-rails 3.x to version 4
28

39
RSpec Rails 4 is a major version under semantic versioning, it allowed us to change the supported Rails versions to 5 and 6 only. There are no changes required to upgrade to RSpec Rails 4 if you are using Rails 5 or 6.

lib/generators/rspec/mailer/templates/mailer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require "rails_helper"
22

33
<% module_namespacing do -%>
4-
RSpec.describe <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>, <%= type_metatag(:mailer) %> do
4+
RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
55
<% for action in actions -%>
66
describe "<%= action %>" do
7-
let(:mail) { <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %> }
7+
let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
88
99
it "renders the headers" do
1010
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)

lib/generators/rspec/mailer/templates/preview.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview
55

66
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
77
def <%= action %>
8-
<%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %>
8+
<%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
99
end
1010
<% end -%>
1111

lib/generators/rspec/scaffold/templates/controller_spec.rb

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@
4646
describe "GET #index" do
4747
it "returns a success response" do
4848
<%= class_name %>.create! valid_attributes
49-
<% if Rails::VERSION::STRING < '5.0' -%>
50-
get :index, {}, valid_session
51-
<% else -%>
5249
get :index, params: {}, session: valid_session
53-
<% end -%>
5450
expect(response).to be_successful
5551
end
5652
end
@@ -59,34 +55,22 @@
5955
describe "GET #show" do
6056
it "returns a success response" do
6157
<%= file_name %> = <%= class_name %>.create! valid_attributes
62-
<% if Rails::VERSION::STRING < '5.0' -%>
63-
get :show, {id: <%= file_name %>.to_param}, valid_session
64-
<% else -%>
6558
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
66-
<% end -%>
6759
expect(response).to be_successful
6860
end
6961
end
7062
7163
describe "GET #new" do
7264
it "returns a success response" do
73-
<% if Rails::VERSION::STRING < '5.0' -%>
74-
get :new, {}, valid_session
75-
<% else -%>
7665
get :new, params: {}, session: valid_session
77-
<% end -%>
7866
expect(response).to be_successful
7967
end
8068
end
8169
8270
describe "GET #edit" do
8371
it "returns a success response" do
8472
<%= file_name %> = <%= class_name %>.create! valid_attributes
85-
<% if Rails::VERSION::STRING < '5.0' -%>
86-
get :edit, {id: <%= file_name %>.to_param}, valid_session
87-
<% else -%>
8873
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
89-
<% end -%>
9074
expect(response).to be_successful
9175
end
9276
end
@@ -95,31 +79,19 @@
9579
context "with valid params" do
9680
it "creates a new <%= class_name %>" do
9781
expect {
98-
<% if Rails::VERSION::STRING < '5.0' -%>
99-
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
100-
<% else -%>
10182
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
102-
<% end -%>
10383
}.to change(<%= class_name %>, :count).by(1)
10484
end
10585
10686
it "redirects to the created <%= ns_file_name %>" do
107-
<% if Rails::VERSION::STRING < '5.0' -%>
108-
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
109-
<% else -%>
11087
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
111-
<% end -%>
11288
expect(response).to redirect_to(<%= class_name %>.last)
11389
end
11490
end
11591
11692
context "with invalid params" do
11793
it "returns a success response (i.e. to display the 'new' template)" do
118-
<% if Rails::VERSION::STRING < '5.0' -%>
119-
post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
120-
<% else -%>
12194
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
122-
<% end -%>
12395
expect(response).to be_successful
12496
end
12597
end
@@ -133,34 +105,22 @@
133105
134106
it "updates the requested <%= ns_file_name %>" do
135107
<%= file_name %> = <%= class_name %>.create! valid_attributes
136-
<% if Rails::VERSION::STRING < '5.0' -%>
137-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
138-
<% else -%>
139108
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
140-
<% end -%>
141109
<%= file_name %>.reload
142110
skip("Add assertions for updated state")
143111
end
144112
145113
it "redirects to the <%= ns_file_name %>" do
146114
<%= file_name %> = <%= class_name %>.create! valid_attributes
147-
<% if Rails::VERSION::STRING < '5.0' -%>
148-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
149-
<% else -%>
150115
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
151-
<% end -%>
152116
expect(response).to redirect_to(<%= file_name %>)
153117
end
154118
end
155119
156120
context "with invalid params" do
157121
it "returns a success response (i.e. to display the 'edit' template)" do
158122
<%= file_name %> = <%= class_name %>.create! valid_attributes
159-
<% if Rails::VERSION::STRING < '5.0' -%>
160-
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
161-
<% else -%>
162123
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
163-
<% end -%>
164124
expect(response).to be_successful
165125
end
166126
end
@@ -170,21 +130,13 @@
170130
it "destroys the requested <%= ns_file_name %>" do
171131
<%= file_name %> = <%= class_name %>.create! valid_attributes
172132
expect {
173-
<% if Rails::VERSION::STRING < '5.0' -%>
174-
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
175-
<% else -%>
176133
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
177-
<% end -%>
178134
}.to change(<%= class_name %>, :count).by(-1)
179135
end
180136
181137
it "redirects to the <%= table_name %> list" do
182138
<%= file_name %> = <%= class_name %>.create! valid_attributes
183-
<% if Rails::VERSION::STRING < '5.0' -%>
184-
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
185-
<% else -%>
186139
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
187-
<% end -%>
188140
expect(response).to redirect_to(<%= index_helper %>_url)
189141
end
190142
end

lib/generators/rspec/scaffold/templates/edit_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
1717
<% for attribute in output_attributes -%>
1818
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
19-
<% if Rails.version.to_f >= 5.1 -%>
2019
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
21-
<% else -%>
22-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
23-
<% end -%>
2420
<% end -%>
2521
end
2622
end

lib/generators/rspec/scaffold/templates/new_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
1616
<% for attribute in output_attributes -%>
1717
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
18-
<% if Rails.version.to_f >= 5.1 -%>
1918
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20-
<% else -%>
21-
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
22-
<% end -%>
2319
<% end -%>
2420
end
2521
end

0 commit comments

Comments
 (0)