Skip to content
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

Support Rails 6.1 #2398

Merged
merged 33 commits into from Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
93a2a70
Setup rails 6.1 builds
JonRowe Oct 15, 2020
3e07b34
Switch accessor for fixture path in file upload support for 6.1
JonRowe Oct 15, 2020
5081f47
Fix controller spec on Rails 6.1
JonRowe Oct 16, 2020
62b8350
Fix view specs on Rails 6.1
JonRowe Oct 16, 2020
61a34d3
Update expected rspec versions
JonRowe Oct 30, 2020
bce2fac
Merge pull request #2403 from PlayerData/rails-6-1-dev
JonRowe Nov 15, 2020
80c82f3
Update expected rspec versions
JonRowe Oct 30, 2020
8658247
Merge pull request #2399 from ThHareau/feat/ticket-2375
pirj Oct 31, 2020
dee0214
Changelog for #2399
JonRowe Nov 1, 2020
9cf2b1f
Add exception for rspec ci
JonRowe Nov 17, 2020
b01ebbe
Merge pull request #2404 from rspec/move-to-github-actions
JonRowe Nov 23, 2020
ac7e9fe
Merge branch 'rails-6-1-dev' into build-updates
JonRowe Nov 26, 2020
fb55a77
Merge pull request #2407 from rspec/build-updates
JonRowe Nov 26, 2020
e83c996
Add 6.1.0 to matrix
benoittgt Dec 2, 2020
a90e52f
Use mailbox_for when available
benoittgt Nov 3, 2020
d61f35b
Skip test for deprecated support of relative paths to `render file:`
benoittgt Nov 1, 2020
b5337fa
Replace deprecated parent method with module_parent
JonRowe Dec 11, 2020
db71614
Merge pull request #2413 from rspec/update-builds-for-6-1
JonRowe Dec 11, 2020
4e88eb3
Merge branch 'main' into rails-6-1-dev
JonRowe Dec 18, 2020
7f2a6f4
Update ci.yml
JonRowe Dec 27, 2020
040fecc
Add testing snippets
pirj Jan 14, 2021
23c42e7
Fix WrongScopeError when use_active_record = false
pirj Dec 23, 2020
3ddfb3a
Merge pull request #2423 from rspec/fix-wrong-scope-error
pirj Jan 20, 2021
1cedd98
Add a regression test for a removed method in 6.1
benoittgt Dec 10, 2020
ba5bab2
Merge pull request #2455 from rspec/add-assert_nothing_raised-regress…
JonRowe Feb 2, 2021
9398cc8
Remove Rails 7 builds against Ruby < 2.7
pirj Feb 18, 2021
9883300
Merge pull request #2462 from rspec/reduce-matrix-to-run-rails-master…
JonRowe Feb 18, 2021
8edb660
Add snippets for method collision on :name and :method_name
benoittgt Feb 17, 2021
4aa5e0b
Prevent collisions on let :name and :method_name in rspec-rails examples
benoittgt Feb 17, 2021
ee760f2
@example resolve to nil, self: RSpec::ExampleGroups::ObservesACallToName
benoittgt Feb 18, 2021
9272757
Merge pull request #2461 from rspec/rails-6-1-issue-2451-dev
JonRowe Feb 20, 2021
5874755
Changelog for #2461
JonRowe Feb 20, 2021
b45312a
Merge branch 'main' into rails-6-1-dev
JonRowe Mar 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -16,8 +16,41 @@ jobs:
fail-fast: false
matrix:
include:
# Rails Master builds >= 2.5
- ruby: 3.0
allow_failure: true
env:
RAILS_VERSION: 'master'
- ruby: 2.7
allow_failure: true
env:
RAILS_VERSION: 'master'
- ruby: 2.6
allow_failure: true
env:
RAILS_VERSION: 'master'
- ruby: 2.5
allow_failure: true
env:
RAILS_VERSION: 'master'

# Rails 6.1.0 builds >= 2.5
- ruby: 3.0
allow_failure: true
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.7
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.6
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.5
env:
RAILS_VERSION: '~> 6.1.0'

# Rails 6.0 builds >= 2.5.0
- ruby: 3.0.0-preview2
- ruby: 3.0
env:
RAILS_VERSION: '~> 6.0.0'
- ruby: 2.7
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -38,6 +38,14 @@ script: "script/run_build 2>&1"

matrix:
include:
# Rails 6.1 builds >= 2.5
- jdk: oraclejdk11
env:
- RAILS_VERSION='master'
- JRUBY_OPT=--dev
- JAVA_OPTS="--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.security=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.security.cert=ALL-UNNAMED --add-opens=java.base/java.util.zip=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util.regex=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/javax.crypto=ALL-UNNAMED --add-opens=java.management/sun.management=ALL-UNNAMED"

# Rails 6.0 builds >= 2.5.0
- rvm: jruby-head
jdk: oraclejdk11
env:
Expand Down
15 changes: 15 additions & 0 deletions BUILD_DETAIL.md
Expand Up @@ -66,6 +66,21 @@ $ bundle exec cucumber
$ bin/cucumber
```

## Snippets

RSpec Rails uses snippets, self-contained examples that are used to cover
cases and regressions that don't need a full-blown example application to
reproduce.

Snippets reuse the already installed gems, and don't attempt to install gem
versions that are not on the system already to prevent version mismatches.

Run with:

```
$ script/run_snippets.sh
```

## YARD documentation

RSpec uses [YARD](https://yardoc.org/) for API documentation on the [rspec.info site](https://rspec.info/).
Expand Down
7 changes: 7 additions & 0 deletions Changelog.md
@@ -1,3 +1,8 @@
### Rails 6.1 Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/main...rails-6-1-dev)
pirj marked this conversation as resolved.
Show resolved Hide resolved

* Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)

### Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.1...main)

Expand All @@ -11,6 +16,7 @@ Enhancements:
(Andrew W. Lee, #2372)
* Improve request spec "controller" scafold when no action is specified.
(Thomas Hareau, #2399)
* Introduce testing snippets concept (Phil Pirozhkov, Benoit Tigeot, #2423)

Bug Fixes:

Expand All @@ -20,6 +26,7 @@ Bug Fixes:
(Phil Pirozhkov, Jon Rowe, #2353, #2354)
* Remove old #fixture_path feature detection code which broke under newer Rails.
(Koen Punt, Jon Rowe, #2370)
* Fix an error when `use_active_record` is `false` (Phil Pirozhkov, #2423)

### 4.0.1 / 2020-05-16
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0...v4.0.1)
Expand Down
21 changes: 1 addition & 20 deletions Gemfile
@@ -1,6 +1,4 @@
source "https://rubygems.org"
version_file = File.expand_path('.rails-version', __dir__)
RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ""

gemspec

Expand All @@ -22,28 +20,11 @@ end

gem 'capybara'

MAJOR =
case RAILS_VERSION
when /5-2-stable/
5
when /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

# Until 1.13.2 is released due to Rubygems usage
gem 'ffi', '~> 1.12.0'

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'
2 changes: 1 addition & 1 deletion Gemfile-rails-dependencies
@@ -1,7 +1,7 @@
version_file = File.expand_path("../.rails-version", __FILE__)

case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
when /main/
when /master/
gem "rails", :git => "https://github.com/rails/rails.git"
gem "arel", :git => "https://github.com/rails/arel.git"
gem "journey", :git => "https://github.com/rails/journey.git"
Expand Down
20 changes: 20 additions & 0 deletions Gemfile-sqlite-dependencies
@@ -0,0 +1,20 @@
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 /master/, /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
11 changes: 7 additions & 4 deletions Rakefile
Expand Up @@ -27,10 +27,13 @@ RSpec::Core::RakeTask.new(:spec) do |t|
end

Cucumber::Rake::Task.new(:cucumber) do |t|
version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")[/\d[\.-]\d/].tr('-', '.')
if version == "main" || version.nil?
version = Float::INFINITY
end
string_version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")
version =
if string_version == "master" || string_version.nil?
Float::INFINITY
else
string_version[/\d[\.-]\d/].tr('-', '.')
end
tags = []

if version.to_f >= 5.1
Expand Down
17 changes: 11 additions & 6 deletions example_app_generator/generate_action_mailer_specs.rb
Expand Up @@ -14,15 +14,20 @@
end
end
CODE
gsub_file 'config/initializers/action_mailer.rb',
/ExampleApp/,
Rails.application.class.parent.to_s

rails_parent =
if Rails.version.to_f >= 6.0
Rails.application.class.module_parent.to_s
else
Rails.application.class.parent.to_s
end

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

copy_file 'spec/support/default_preview_path'
chmod 'spec/support/default_preview_path', 0755
gsub_file 'spec/support/default_preview_path',
/ExampleApp/,
Rails.application.class.parent.to_s
gsub_file 'spec/support/default_preview_path', /ExampleApp/, rails_parent

if skip_active_record?
comment_lines 'spec/support/default_preview_path', /active_record/
comment_lines 'spec/support/default_preview_path', /active_storage/
Expand Down
2 changes: 2 additions & 0 deletions features/controller_specs/anonymous_controller.feature
Expand Up @@ -101,6 +101,8 @@ 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
Expand Down
41 changes: 31 additions & 10 deletions lib/rspec/rails/fixture_file_upload_support.rb
Expand Up @@ -6,21 +6,42 @@ module FixtureFileUploadSupport

private

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
# 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
# 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
end

class RailsFixtureFileWrapper
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)

if ::Rails.version.to_f >= 6.1
include ActiveSupport::Testing::FileFixtures
end

class << self
attr_accessor :fixture_path

Expand Down
14 changes: 7 additions & 7 deletions lib/rspec/rails/fixture_support.rb
Expand Up @@ -9,6 +9,13 @@ module FixtureSupport
include RSpec::Rails::MinitestAssertionAdapter
include ActiveRecord::TestFixtures

if ::Rails.version.to_f >= 6.1
# @private return the example name for TestFixtures
def name
@example
end
end

included do
if RSpec.configuration.use_active_record?
include Fixtures
Expand Down Expand Up @@ -50,13 +57,6 @@ def proxy_method_warning_if_called_in_before_context_scope(method_name)
end
end
end

if ::Rails.version.to_f >= 6.1
# @private return the example name for TestFixtures
def name
@example
end
end
end
end
end
Expand Down
19 changes: 14 additions & 5 deletions lib/rspec/rails/matchers/action_mailbox.rb
Expand Up @@ -22,11 +22,20 @@ def initialize(message)
@inbound_email = create_inbound_email(message)
end

def matches?(mailbox)
@mailbox = mailbox
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
if defined?(::ApplicationMailbox) && ::ApplicationMailbox.router.respond_to?(:mailbox_for)
def matches?(mailbox)
@mailbox = mailbox
@receiver = ApplicationMailbox.router.mailbox_for(inbound_email)

@receiver == @mailbox
@receiver == @mailbox
end
else
def matches?(mailbox)
@mailbox = mailbox
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)

@receiver == @mailbox
end
end

def failure_message
Expand All @@ -41,7 +50,7 @@ def failure_message_when_negated
"expected #{describe_inbound_email} not to route to #{mailbox}"
end

private
private

attr_reader :inbound_email, :mailbox, :receiver

Expand Down
2 changes: 2 additions & 0 deletions script/run_build
Expand Up @@ -20,6 +20,8 @@ fi

fold "cukes" run_cukes

fold "snippets" script/run_snippets.sh

if documentation_enforced; then
fold "doc check" check_documentation_coverage
fi
Expand Down
13 changes: 13 additions & 0 deletions script/run_snippets.sh
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

(
cd snippets
# This is required to load `bundle/inline`
unset RUBYOPT
for snippet in *.rb;
do
echo Running $snippet
ruby $snippet
done
)