Skip to content

Commit b694a75

Browse files
authored
Merge pull request #2398 from rspec/rails-6-1-dev
Support Rails 6.1
2 parents 483e487 + b45312a commit b694a75

13 files changed

+144
-33
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,31 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
include:
19+
# Rails Master (7.0) builds >= 2.7
20+
- ruby: 3.0
21+
allow_failure: true
22+
env:
23+
RAILS_VERSION: 'master'
24+
- ruby: 2.7
25+
allow_failure: true
26+
env:
27+
RAILS_VERSION: 'master'
28+
29+
# Rails 6.1 builds >= 2.5
30+
- ruby: 3.0
31+
allow_failure: true
32+
env:
33+
RAILS_VERSION: '~> 6.1.0'
34+
- ruby: 2.7
35+
env:
36+
RAILS_VERSION: '~> 6.1.0'
37+
- ruby: 2.6
38+
env:
39+
RAILS_VERSION: '~> 6.1.0'
40+
- ruby: 2.5
41+
env:
42+
RAILS_VERSION: '~> 6.1.0'
43+
1944
# Rails 6.0 builds >= 2.5.0
2045
- ruby: 3.0
2146
env:

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ script: "script/run_build 2>&1"
3838

3939
matrix:
4040
include:
41+
# Rails 6.1 builds >= 2.5
42+
- jdk: oraclejdk11
43+
env:
44+
- RAILS_VERSION='master'
45+
- JRUBY_OPT=--dev
46+
- 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"
47+
48+
# Rails 6.0 builds >= 2.5.0
4149
- rvm: jruby-head
4250
jdk: oraclejdk11
4351
env:

Changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
### Development
2+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.0...main)
3+
4+
* Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)
5+
* Support for Rails 6.1. (Benoit Tigeot, Jon Rowe, Phil Pirozhkov, and more #2398)
6+
17
### 4.1.0 / 2021-03-06
2-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.2...v4.1.0)
38

49
Enhancements:
510

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

3036
### 4.0.1 / 2020-05-16
3137
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0...v4.0.1)

Gemfile-rails-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version_file = File.expand_path("../.rails-version", __FILE__)
22

33
case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
4-
when /main/
4+
when /master/
55
gem "rails", :git => "https://github.com/rails/rails.git"
66
gem "arel", :git => "https://github.com/rails/arel.git"
77
gem "journey", :git => "https://github.com/rails/journey.git"

Rakefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ RSpec::Core::RakeTask.new(:spec) do |t|
2727
end
2828

2929
Cucumber::Rake::Task.new(:cucumber) do |t|
30-
version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")[/\d[\.-]\d/].tr('-', '.')
31-
if version == "main" || version.nil?
32-
version = Float::INFINITY
33-
end
30+
string_version = ENV.fetch("RAILS_VERSION", "~> 6.0.0")
31+
version =
32+
if string_version == "master" || string_version.nil?
33+
Float::INFINITY
34+
else
35+
string_version[/\d[\.-]\d/].tr('-', '.')
36+
end
3437
tags = []
3538

3639
if version.to_f >= 5.1

example_app_generator/generate_action_mailer_specs.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
end
1515
end
1616
CODE
17-
gsub_file 'config/initializers/action_mailer.rb',
18-
/ExampleApp/,
19-
Rails.application.class.parent.to_s
17+
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
24+
25+
gsub_file 'config/initializers/action_mailer.rb', /ExampleApp/, rails_parent
2026

2127
copy_file 'spec/support/default_preview_path'
2228
chmod 'spec/support/default_preview_path', 0755
23-
gsub_file 'spec/support/default_preview_path',
24-
/ExampleApp/,
25-
Rails.application.class.parent.to_s
29+
gsub_file 'spec/support/default_preview_path', /ExampleApp/, rails_parent
30+
2631
if skip_active_record?
2732
comment_lines 'spec/support/default_preview_path', /active_record/
2833
comment_lines 'spec/support/default_preview_path', /active_storage/

features/controller_specs/anonymous_controller.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ 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
104106
Scenario: Specify error handling in `ApplicationController` with render :file
105107
Given a file named "spec/controllers/application_controller_spec.rb" with:
106108
"""ruby

lib/rspec/rails/fixture_file_upload_support.rb

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,42 @@ module FixtureFileUploadSupport
66

77
private
88

9-
def rails_fixture_file_wrapper
10-
RailsFixtureFileWrapper.fixture_path = nil
11-
resolved_fixture_path =
12-
if respond_to?(:fixture_path) && !fixture_path.nil?
13-
fixture_path.to_s
14-
else
15-
(RSpec.configuration.fixture_path || '').to_s
16-
end
17-
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
18-
RailsFixtureFileWrapper.instance
9+
# In Rails 6.2 fixture file path needs to be relative to `file_fixture_path` instead, this change
10+
# was brought in with a deprecation warning on 6.1. In Rails 6.2 expect to rework this to remove
11+
# the old accessor.
12+
if ::Rails.version.to_f >= 6.1
13+
def rails_fixture_file_wrapper
14+
RailsFixtureFileWrapper.file_fixture_path = nil
15+
resolved_fixture_path =
16+
if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
17+
file_fixture_path.to_s
18+
else
19+
(RSpec.configuration.fixture_path || '').to_s
20+
end
21+
RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
22+
RailsFixtureFileWrapper.instance
23+
end
24+
else
25+
def rails_fixture_file_wrapper
26+
RailsFixtureFileWrapper.fixture_path = nil
27+
resolved_fixture_path =
28+
if respond_to?(:fixture_path) && !fixture_path.nil?
29+
fixture_path.to_s
30+
else
31+
(RSpec.configuration.fixture_path || '').to_s
32+
end
33+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
34+
RailsFixtureFileWrapper.instance
35+
end
1936
end
2037

2138
class RailsFixtureFileWrapper
2239
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
2340

41+
if ::Rails.version.to_f >= 6.1
42+
include ActiveSupport::Testing::FileFixtures
43+
end
44+
2445
class << self
2546
attr_accessor :fixture_path
2647

lib/rspec/rails/matchers/action_mailbox.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@ def initialize(message)
2222
@inbound_email = create_inbound_email(message)
2323
end
2424

25-
def matches?(mailbox)
26-
@mailbox = mailbox
27-
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
25+
if defined?(::ApplicationMailbox) && ::ApplicationMailbox.router.respond_to?(:mailbox_for)
26+
def matches?(mailbox)
27+
@mailbox = mailbox
28+
@receiver = ApplicationMailbox.router.mailbox_for(inbound_email)
2829

29-
@receiver == @mailbox
30+
@receiver == @mailbox
31+
end
32+
else
33+
def matches?(mailbox)
34+
@mailbox = mailbox
35+
@receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
36+
37+
@receiver == @mailbox
38+
end
3039
end
3140

3241
def failure_message
@@ -41,7 +50,7 @@ def failure_message_when_negated
4150
"expected #{describe_inbound_email} not to route to #{mailbox}"
4251
end
4352

44-
private
53+
private
4554

4655
attr_reader :inbound_email, :mailbox, :receiver
4756

spec/rspec/rails/example/controller_example_group_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ def my_helper
3636
"other_value"
3737
end
3838
end
39-
config.include mod
39+
40+
# Rails 6.1 removes config from ./activerecord/lib/active_record/test_fixtures.rb
41+
if respond_to?(:config)
42+
config.include mod
43+
else
44+
ActiveRecord::Base.include mod
45+
end
46+
4047
group.class_exec do
4148
let(:my_helper) { "my_value" }
4249
end

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module ::Namespaced; module ThingsHelper; end; end
1313
group = RSpec::Core::ExampleGroup.describe('things/show.html.erb') do
1414
def self.helper(*); end # Stub method
1515
end
16+
allow(group).to receive(:helper)
1617
expect(group).to receive(:helper).with(ThingsHelper)
1718
group.class_exec do
1819
include ViewExampleGroup
@@ -23,6 +24,7 @@ def self.helper(*); end # Stub method
2324
group = RSpec::Core::ExampleGroup.describe('namespaced/things/show.html.erb') do
2425
def self.helper(*); end # Stub method
2526
end
27+
allow(group).to receive(:helper)
2628
expect(group).to receive(:helper).with(Namespaced::ThingsHelper)
2729
group.class_exec do
2830
include ViewExampleGroup
@@ -66,6 +68,7 @@ module ::ApplicationHelper; end
6668
group = RSpec::Core::ExampleGroup.describe('bars/new.html.erb') do
6769
def self.helper(*); end # Stub method
6870
end
71+
allow(group).to receive(:helper)
6972
expect(group).to receive(:helper).with(ApplicationHelper)
7073
group.class_exec do
7174
include ViewExampleGroup

spec/rspec/rails/fixture_file_upload_support_spec.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,43 @@ module RSpec::Rails
33
context 'with fixture path set in config' do
44
it 'resolves fixture file' do
55
RSpec.configuration.fixture_path = File.dirname(__FILE__)
6-
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
6+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
77
end
88

99
it 'resolves supports `Pathname` objects' do
1010
RSpec.configuration.fixture_path = Pathname(File.dirname(__FILE__))
11-
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
11+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
1212
end
1313
end
1414

1515
context 'with fixture path set in spec' do
1616
it 'resolves fixture file' do
17-
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__)).run).to be true
17+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__))
1818
end
1919
end
2020

2121
context 'with fixture path not set' do
2222
it 'resolves fixture using relative path' do
2323
RSpec.configuration.fixture_path = nil
24-
expect(fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb').run).to be true
24+
expect_to_pass fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb')
2525
end
2626
end
2727

28+
def expect_to_pass(group)
29+
result = group.run(failure_reporter)
30+
failure_reporter.exceptions.map { |e| raise e }
31+
expect(result).to be true
32+
end
33+
2834
def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
2935
RSpec::Core::ExampleGroup.describe do
3036
include RSpec::Rails::FixtureFileUploadSupport
3137

32-
self.fixture_path = fixture_path
38+
if ::Rails.version.to_f >= 6.1
39+
self.file_fixture_path = fixture_path
40+
else
41+
self.fixture_path = fixture_path
42+
end
3343

3444
it 'supports fixture file upload' do
3545
file = fixture_file_upload(fixture_name)

spec/rspec/rails/matchers/active_job_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,16 @@ def self.name; "LoggingJob"; end
702702
}.to raise_error(/expected to perform exactly 1 jobs, but performed 0/)
703703
end
704704
end
705+
706+
describe 'Active Job test helpers' do
707+
include ActiveJob::TestHelper
708+
709+
it 'does not raise that "assert_nothing_raised" is undefined' do
710+
expect {
711+
perform_enqueued_jobs do
712+
:foo
713+
end
714+
}.to_not raise_error
715+
end
716+
end
705717
end

0 commit comments

Comments
 (0)