Skip to content

Add Ruby 3.1 (without Rails 7 support) to main #2563

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

Merged
merged 2 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,10 @@ jobs:
fail-fast: false
matrix:
include:
# Edge Rails (7.1) builds >= 2.7
- ruby: '3.0'
allow_failure: true
env:
RAILS_VERSION: 'main'
- ruby: 2.7
allow_failure: true
env:
RAILS_VERSION: 'main'

# Rails 7.0 builds >= 2.7
- ruby: 3.1
allow_failure: true
env:
RAILS_VERSION: '~> 7.0.0'
- ruby: '3.0'
allow_failure: true
env:
RAILS_VERSION: '~> 7.0.0'
- ruby: 2.7
allow_failure: true
env:
RAILS_VERSION: '~> 7.0.0'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted this part because main supports Rails 7.

# Rails 6.1 builds >= 2.5
- ruby: '3.1'
env:
RAILS_VERSION: '~> 6.1.0'
- ruby: '3.0'
env:
RAILS_VERSION: '~> 6.1.0'
Expand Down
4 changes: 4 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ Layout/LineLength:
# Over time we'd like to get this down, but this is what we're at now.
Metrics/MethodLength:
Max: 43 # default: 10

Metrics/ClassLength:
Exclude:
- lib/rspec/rails/matchers/have_enqueued_mail.rb
4 changes: 4 additions & 0 deletions lib/rspec/rails/feature_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def has_action_mailbox?
defined?(::ActionMailbox)
end

def ruby_3_1?
RUBY_VERSION >= "3.1"
end

def type_metatag(type)
"type: :#{type}"
end
Expand Down
20 changes: 16 additions & 4 deletions lib/rspec/rails/matchers/have_enqueued_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
module RSpec
module Rails
module Matchers
# rubocop: disable Metrics/ClassLength
# Matcher class for `have_enqueued_mail`. Should not be instantiated directly.
#
# @private
Expand Down Expand Up @@ -91,7 +90,7 @@ def arguments_match?(job)

def process_arguments(job, given_mail_args)
# Old matcher behavior working with all builtin classes but ActionMailer::MailDeliveryJob
return given_mail_args unless defined?(ActionMailer::MailDeliveryJob) && job[:job] <= ActionMailer::MailDeliveryJob
return given_mail_args if use_given_mail_args?(job)

# If matching args starts with a hash and job instance has params match with them
if given_mail_args.first.is_a?(Hash) && job[:args][3]['params'].present?
Expand All @@ -101,6 +100,13 @@ def process_arguments(job, given_mail_args)
end
end

def use_given_mail_args?(job)
return true if FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
return false if FeatureCheck.ruby_3_1?

!(FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob)
end

def base_mailer_args
[mailer_class_name, @method_name.to_s, MAILER_JOB_METHOD]
end
Expand Down Expand Up @@ -143,13 +149,20 @@ def mail_job_message(job)
mailer_args = deserialize_arguments(job)[3..-1]
mailer_args = mailer_args.first[:args] if unified_mail?(job)
msg_parts = []
msg_parts << "with #{mailer_args}" if mailer_args.any?
display_args = display_mailer_args(mailer_args)
msg_parts << "with #{display_args}" if display_args.any?
msg_parts << "on queue #{job[:queue]}" if job[:queue] && job[:queue] != 'mailers'
msg_parts << "at #{Time.at(job[:at])}" if job[:at]

"#{mailer_method} #{msg_parts.join(', ')}".strip
end

def display_mailer_args(mailer_args)
return mailer_args unless mailer_args.first.is_a?(Hash) && mailer_args.first.key?(:args)

mailer_args.first[:args]
end

def legacy_mail?(job)
RSpec::Rails::FeatureCheck.has_action_mailer_legacy_delivery_job? && job[:job] <= ActionMailer::DeliveryJob
end
Expand All @@ -162,7 +175,6 @@ def unified_mail?(job)
RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob
end
end
# rubocop: enable Metrics/ClassLength

# @api public
# Passes if an email has been enqueued inside block.
Expand Down