Skip to content

Commit

Permalink
Merge pull request #2476 from rspec/prep-version-5
Browse files Browse the repository at this point in the history
Prep version 5
  • Loading branch information
JonRowe committed Mar 9, 2021
2 parents b694a75 + 1543e02 commit f249b48
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 312 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,6 @@ jobs:
- ruby: 2.2.10
env:
RAILS_VERSION: '5-2-stable'
# Rails 5.1 Builds >= 2.2.2
- ruby: 2.6.6
env:
RAILS_VERSION: '~> 5.1.0'
- ruby: 2.5.8
env:
RAILS_VERSION: '~> 5.1.0'
- ruby: 2.4.10
env:
RAILS_VERSION: '~> 5.1.0'
- ruby: 2.3.8
env:
RAILS_VERSION: '~> 5.1.0'
- ruby: 2.2.10
env:
RAILS_VERSION: '~> 5.1.0'
# Rails 5.0 Builds >= 2.2.2
- ruby: 2.6.6
env:
RAILS_VERSION: '~> 5.0.0'
- ruby: 2.5.8
env:
RAILS_VERSION: '~> 5.0.0'
- ruby: 2.4.10
env:
RAILS_VERSION: '~> 5.0.0'
- ruby: 2.3.8
env:
RAILS_VERSION: '~> 5.0.0'
- ruby: 2.2.10
env:
RAILS_VERSION: '~> 5.0.0'
env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
### Development
### 5.0.0
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.0...main)

Enhancements:

* Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)
* Support for Rails 6.1. (Benoit Tigeot, Jon Rowe, Phil Pirozhkov, and more #2398)

Breaking Changes:

* Drop support for Rails below 5.2.

### 4.1.0 / 2021-03-06

Enhancements:
Expand Down
6 changes: 3 additions & 3 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ when /master/
gem 'selenium-webdriver', require: false
when /stable$/
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport activejob actionview]
gem 'puma', "3.12.1" if version > '5-0-stable'
gem 'puma', "3.12.1"
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]

gem_list.each do |rails_gem|
Expand All @@ -31,7 +31,7 @@ when nil, false, ""
else
gem "rails", version
gem "sprockets", '~> 3.0' if RUBY_VERSION < '2.5'
gem "puma" if version >= '5-1-stable'
gem "puma"
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
gem 'selenium-webdriver', require: false if version >= '5'
gem 'selenium-webdriver', require: false
end
14 changes: 1 addition & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ require 'cucumber/rake/task'

def rails_template_command
require "rails/version"
if Rails.version.to_f >= 5.0
"app:template"
else
"rails:template"
end
"app:template"
end

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

if version.to_f >= 5.1
tags << "~@rails_pre_5.1"
end

if version.to_f == 5.0
tags << "~@system_test"
end

if version.to_f >= 6.0
tags << "~@rails_pre_6"
end
Expand Down
18 changes: 6 additions & 12 deletions example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
gsub_file "Gemfile", /.*puma.*/, ''
gsub_file "Gemfile", /.*bootsnap.*/, ''

# We soft-support Rails 4.2. `rails-controller-testing` only supports Rails 5+.
# This conditional is to facilitate local testing against Rails 4.2.
if Rails::VERSION::STRING >= '5'
append_to_file 'Gemfile', "gem 'rails-controller-testing'\n"
end
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'"
Expand All @@ -47,14 +43,12 @@
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'"
end

if Rails::VERSION::STRING >= "5.1.0"
# 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'"
end
# 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 >= '5.2.0' && Rails::VERSION::STRING < '6'
if Rails::VERSION::STRING < '6'
copy_file sqlite_initializer, 'config/initializers/sqlite3_fix.rb'
end

Expand Down
29 changes: 0 additions & 29 deletions features/feature_specs/feature_spec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,6 @@ Feature: Feature spec
[customer](http://c2.com/cgi/wiki?CustomerTest) and [acceptance](http://c2.com/cgi/wiki?AcceptanceTest) tests. When capybara is required it sets
`:type => :feature` automatically for you.

@rails_pre_5.1
Scenario: Feature specs are skipped without Capybara
Given a file named "spec/features/widget_management_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.feature "Widget management", :type => :feature do
scenario "User creates a new widget" do
visit "/widgets/new"
fill_in "Name", :with => "My Widget"
click_button "Create Widget"
expect(page).to have_text("Widget was successfully created.")
end
end
"""
When I run `rspec spec/features/widget_management_spec.rb`
Then the exit status should be 0
And the output should contain "1 example, 0 failures, 1 pending"
And the output should contain:
"""
Pending: (Failures listed here are expected and do not affect your suite's status)
1) Widget management User creates a new widget
# Feature specs require the Capybara (https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later.
# ./spec/features/widget_management_spec.rb:4
"""

@capybara
Scenario: specify creating a Widget by driving the application with capybara
Given a file named "spec/features/widget_management_spec.rb" with:
Expand Down
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 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.

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

# Upgrading from rspec-rails 3.x to version 4

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.
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/rspec/mailer/templates/mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "rails_helper"

<% module_namespacing do -%>
RSpec.describe <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>, <%= type_metatag(:mailer) %> do
RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
<% for action in actions -%>
describe "<%= action %>" do
let(:mail) { <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %> }
let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
it "renders the headers" do
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/mailer/templates/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview

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

Expand Down
48 changes: 0 additions & 48 deletions lib/generators/rspec/scaffold/templates/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@
describe "GET #index" do
it "returns a success response" do
<%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
get :index, {}, valid_session
<% else -%>
get :index, params: {}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end
Expand All @@ -59,34 +55,22 @@
describe "GET #show" do
it "returns a success response" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
get :show, {id: <%= file_name %>.to_param}, valid_session
<% else -%>
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end

describe "GET #new" do
it "returns a success response" do
<% if Rails::VERSION::STRING < '5.0' -%>
get :new, {}, valid_session
<% else -%>
get :new, params: {}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end

describe "GET #edit" do
it "returns a success response" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
get :edit, {id: <%= file_name %>.to_param}, valid_session
<% else -%>
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end
Expand All @@ -95,31 +79,19 @@
context "with valid params" do
it "creates a new <%= class_name %>" do
expect {
<% if Rails::VERSION::STRING < '5.0' -%>
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
<% else -%>
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
<% end -%>
}.to change(<%= class_name %>, :count).by(1)
end
it "redirects to the created <%= ns_file_name %>" do
<% if Rails::VERSION::STRING < '5.0' -%>
post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
<% else -%>
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
<% end -%>
expect(response).to redirect_to(<%= class_name %>.last)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'new' template)" do
<% if Rails::VERSION::STRING < '5.0' -%>
post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
<% else -%>
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end
Expand All @@ -133,34 +105,22 @@

it "updates the requested <%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
<% else -%>
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
<% end -%>
<%= file_name %>.reload
skip("Add assertions for updated state")
end
it "redirects to the <%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
<% else -%>
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
<% end -%>
expect(response).to redirect_to(<%= file_name %>)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'edit' template)" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
<% else -%>
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
<% end -%>
expect(response).to be_successful
end
end
Expand All @@ -170,21 +130,13 @@
it "destroys the requested <%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
expect {
<% if Rails::VERSION::STRING < '5.0' -%>
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
<% else -%>
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
<% end -%>
}.to change(<%= class_name %>, :count).by(-1)
end
it "redirects to the <%= table_name %> list" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
<% if Rails::VERSION::STRING < '5.0' -%>
delete :destroy, {id: <%= file_name %>.to_param}, valid_session
<% else -%>
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
<% end -%>
expect(response).to redirect_to(<%= index_helper %>_url)
end
end
Expand Down
4 changes: 0 additions & 4 deletions lib/generators/rspec/scaffold/templates/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
<% for attribute in output_attributes -%>
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
<% if Rails.version.to_f >= 5.1 -%>
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
<% else -%>
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
<% end -%>
<% end -%>
end
end
Expand Down
4 changes: 0 additions & 4 deletions lib/generators/rspec/scaffold/templates/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
<% for attribute in output_attributes -%>
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
<% if Rails.version.to_f >= 5.1 -%>
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
<% else -%>
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
<% end -%>
<% end -%>
end
end
Expand Down
Loading

0 comments on commit f249b48

Please sign in to comment.