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 all 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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -16,6 +16,31 @@ jobs:
fail-fast: false
matrix:
include:
# Rails Master (7.0) builds >= 2.7
- ruby: 3.0
allow_failure: true
env:
RAILS_VERSION: 'master'
- ruby: 2.7
allow_failure: true
env:
RAILS_VERSION: 'master'

# Rails 6.1 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
env:
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
8 changes: 7 additions & 1 deletion Changelog.md
@@ -1,5 +1,10 @@
### Development
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.0...main)

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

### 4.1.0 / 2021-03-06
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.2...v4.1.0)

Enhancements:

Expand All @@ -26,6 +31,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
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
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
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
9 changes: 8 additions & 1 deletion spec/rspec/rails/example/controller_example_group_spec.rb
Expand Up @@ -36,7 +36,14 @@ def my_helper
"other_value"
end
end
config.include mod

# Rails 6.1 removes config from ./activerecord/lib/active_record/test_fixtures.rb
if respond_to?(:config)
config.include mod
else
ActiveRecord::Base.include mod
end

group.class_exec do
let(:my_helper) { "my_value" }
end
Expand Down
3 changes: 3 additions & 0 deletions spec/rspec/rails/example/view_example_group_spec.rb
Expand Up @@ -13,6 +13,7 @@ module ::Namespaced; module ThingsHelper; end; end
group = RSpec::Core::ExampleGroup.describe('things/show.html.erb') do
def self.helper(*); end # Stub method
end
allow(group).to receive(:helper)
expect(group).to receive(:helper).with(ThingsHelper)
group.class_exec do
include ViewExampleGroup
Expand All @@ -23,6 +24,7 @@ def self.helper(*); end # Stub method
group = RSpec::Core::ExampleGroup.describe('namespaced/things/show.html.erb') do
def self.helper(*); end # Stub method
end
allow(group).to receive(:helper)
expect(group).to receive(:helper).with(Namespaced::ThingsHelper)
group.class_exec do
include ViewExampleGroup
Expand Down Expand Up @@ -66,6 +68,7 @@ module ::ApplicationHelper; end
group = RSpec::Core::ExampleGroup.describe('bars/new.html.erb') do
def self.helper(*); end # Stub method
end
allow(group).to receive(:helper)
expect(group).to receive(:helper).with(ApplicationHelper)
group.class_exec do
include ViewExampleGroup
Expand Down
20 changes: 15 additions & 5 deletions spec/rspec/rails/fixture_file_upload_support_spec.rb
Expand Up @@ -3,33 +3,43 @@ module RSpec::Rails
context 'with fixture path set in config' do
it 'resolves fixture file' do
RSpec.configuration.fixture_path = File.dirname(__FILE__)
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
end

it 'resolves supports `Pathname` objects' do
RSpec.configuration.fixture_path = Pathname(File.dirname(__FILE__))
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
end
end

context 'with fixture path set in spec' do
it 'resolves fixture file' do
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__)).run).to be true
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__))
end
end

context 'with fixture path not set' do
it 'resolves fixture using relative path' do
RSpec.configuration.fixture_path = nil
expect(fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb').run).to be true
expect_to_pass fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb')
end
end

def expect_to_pass(group)
result = group.run(failure_reporter)
failure_reporter.exceptions.map { |e| raise e }
expect(result).to be true
end

def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
RSpec::Core::ExampleGroup.describe do
include RSpec::Rails::FixtureFileUploadSupport

self.fixture_path = fixture_path
if ::Rails.version.to_f >= 6.1
self.file_fixture_path = fixture_path
else
self.fixture_path = fixture_path
end

it 'supports fixture file upload' do
file = fixture_file_upload(fixture_name)
Expand Down
12 changes: 12 additions & 0 deletions spec/rspec/rails/matchers/active_job_spec.rb
Expand Up @@ -702,4 +702,16 @@ def self.name; "LoggingJob"; end
}.to raise_error(/expected to perform exactly 1 jobs, but performed 0/)
end
end

describe 'Active Job test helpers' do
include ActiveJob::TestHelper

it 'does not raise that "assert_nothing_raised" is undefined' do
expect {
perform_enqueued_jobs do
:foo
end
}.to_not raise_error
end
end
end