diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index c1501c78cd..61cb35e8f8 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -140,8 +140,9 @@ def job_match?(job) def arguments_match?(job) if @args.any? + args = serialize_and_deserialize_arguments(@args) deserialized_args = deserialize_arguments(job) - RSpec::Mocks::ArgumentListMatcher.new(*@args).args_match?(*deserialized_args) + RSpec::Mocks::ArgumentListMatcher.new(*args).args_match?(*deserialized_args) else true end @@ -172,6 +173,13 @@ def set_expected_number(relativity, count) end end + def serialize_and_deserialize_arguments(args) + serialized = ::ActiveJob::Arguments.serialize(args) + ::ActiveJob::Arguments.deserialize(serialized) + rescue ::ActiveJob::SerializationError + args + end + def deserialize_arguments(job) ::ActiveJob::Arguments.deserialize(job[:args]) rescue ::ActiveJob::DeserializationError diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index c85b98a6b2..04c44de9d9 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -328,6 +328,24 @@ def self.name; "LoggingJob"; end expect(arg).to eq("asdf") } end + + if Rails.version.to_f >= 6.0 + it "passes with Time" do + usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z') + + expect { + hello_job.perform_later(usec_time) + }.to have_enqueued_job(hello_job).with(usec_time) + end + + it "passes with ActiveSupport::TimeWithZone" do + usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z').in_time_zone + + expect { + hello_job.perform_later(usec_time) + }.to have_enqueued_job(hello_job).with(usec_time) + end + end end describe "have_been_enqueued" do