diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7101817c51..fa880114d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.travis.yml b/.travis.yml index 4012daadfd..1d48088034 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Changelog.md b/Changelog.md index a3df08ee52..864a7a816b 100644 --- a/Changelog.md +++ b/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: @@ -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) diff --git a/Gemfile-rails-dependencies b/Gemfile-rails-dependencies index 5b3ebda404..03f75abfb2 100644 --- a/Gemfile-rails-dependencies +++ b/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" diff --git a/Rakefile b/Rakefile index f68cb64a6f..ac5a7b39c3 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/example_app_generator/generate_action_mailer_specs.rb b/example_app_generator/generate_action_mailer_specs.rb index 13a1f0a4c0..06833fc1a5 100644 --- a/example_app_generator/generate_action_mailer_specs.rb +++ b/example_app_generator/generate_action_mailer_specs.rb @@ -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/ diff --git a/features/controller_specs/anonymous_controller.feature b/features/controller_specs/anonymous_controller.feature index 7892b4dfac..9baf73fb8d 100644 --- a/features/controller_specs/anonymous_controller.feature +++ b/features/controller_specs/anonymous_controller.feature @@ -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 diff --git a/lib/rspec/rails/fixture_file_upload_support.rb b/lib/rspec/rails/fixture_file_upload_support.rb index bcbc733d74..ef4989c653 100644 --- a/lib/rspec/rails/fixture_file_upload_support.rb +++ b/lib/rspec/rails/fixture_file_upload_support.rb @@ -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 diff --git a/lib/rspec/rails/matchers/action_mailbox.rb b/lib/rspec/rails/matchers/action_mailbox.rb index c5392cb225..de50c69143 100644 --- a/lib/rspec/rails/matchers/action_mailbox.rb +++ b/lib/rspec/rails/matchers/action_mailbox.rb @@ -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 @@ -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 diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index 329626191b..56b53049d1 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -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 diff --git a/spec/rspec/rails/example/view_example_group_spec.rb b/spec/rspec/rails/example/view_example_group_spec.rb index f46f7feb04..9b4dafcc74 100644 --- a/spec/rspec/rails/example/view_example_group_spec.rb +++ b/spec/rspec/rails/example/view_example_group_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/rspec/rails/fixture_file_upload_support_spec.rb b/spec/rspec/rails/fixture_file_upload_support_spec.rb index d7be688d19..af074704dd 100644 --- a/spec/rspec/rails/fixture_file_upload_support_spec.rb +++ b/spec/rspec/rails/fixture_file_upload_support_spec.rb @@ -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) diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index 896cd7db1e..02c3132016 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -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