diff --git a/CHANGES.md b/CHANGES.md index b84c23c..805bcba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +2.2.0 +--- +* Fix typo in README file [bradhaydon#87] +* Fix type in readme [graudeejs#80] +* Matchers::HaveEnqueuedJob breaks on jobs with Hash arguments [erikogan#77] +* have_enqueued_job fails if args includes a Hash bug [gPrado#74] + 2.1.0 --- * ActiveJob support [tarzan#71] diff --git a/README.md b/README.md index d1a2071..d4040a0 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ sidekiq_options retry: 5 # test with... expect(AwesomeJob).to be_retryable true # or it { is_expected.to be_retryable true } -# ...or alternatively specifiy the number of times it should be retried +# ...or alternatively specify the number of times it should be retried expect(AwesomeJob).to be_retryable 5 # or it { is_expected.to be_retryable 5 } # ...or when it should not retry @@ -136,7 +136,7 @@ it { is_expected.to_not be_expired_in 2.hours } ### have_enqueued_job *Describes that there should be an enqueued job with the specified arguments* ```ruby -Awesomejob.perform_async 'Awesome', true +AwesomeJob.perform_async 'Awesome', true # test with... expect(AwesomeJob).to have_enqueued_job('Awesome', true) ``` diff --git a/lib/rspec/sidekiq/matchers/have_enqueued_job.rb b/lib/rspec/sidekiq/matchers/have_enqueued_job.rb index ea87eb5..6fe12b2 100644 --- a/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +++ b/lib/rspec/sidekiq/matchers/have_enqueued_job.rb @@ -9,7 +9,7 @@ class HaveEnqueuedJob attr_reader :klass, :expected_arguments, :actual def initialize(expected_arguments) - @expected_arguments = expected_arguments + @expected_arguments = normalize_arguments(expected_arguments) end def description @@ -53,13 +53,25 @@ def map_arguments(job) end def job_arguments(hash) - hash['arguments'] || hash['args'] unless hash.is_a? Array + hash['arguments'] || hash['args'] if hash.is_a? Hash end def contain_exactly?(arguments) exactly = RSpec::Matchers::BuiltIn::ContainExactly.new(expected_arguments) exactly.matches?(arguments) end + + def normalize_arguments(args) + if args.is_a?(Array) + args.map{ |x| normalize_arguments(x) } + elsif args.is_a?(Hash) + args.each_with_object({}) do |(key, value), hash| + hash[key.to_s] = normalize_arguments(value) + end + else + args + end + end end end end diff --git a/lib/rspec/sidekiq/version.rb b/lib/rspec/sidekiq/version.rb index 51f8d8f..60caaf0 100644 --- a/lib/rspec/sidekiq/version.rb +++ b/lib/rspec/sidekiq/version.rb @@ -1,5 +1,5 @@ module RSpec module Sidekiq - VERSION = '2.1.0' + VERSION = '2.2.0' end end diff --git a/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb b/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb index 7423d4e..182294d 100644 --- a/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +++ b/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb @@ -1,14 +1,15 @@ require 'spec_helper' RSpec.describe RSpec::Sidekiq::Matchers::HaveEnqueuedJob do - let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new ['string', 1, true] } - let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [be_a(String), be_a(Fixnum), true] } + let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new worker_args } + let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [be_a(String), be_a(Fixnum), true, be_a(Hash)] } let(:worker) { create_worker } + let(:worker_args) { ['string', 1, true, {key: 'value', nested: [{hash: true}]}] } let(:active_job) { create_active_job :mailers } let(:resource) { TestResource.new } before(:each) do - worker.perform_async 'string', 1, true + worker.perform_async *worker_args active_job.perform_later 'someResource' active_job.perform_later(resource) TestActionMailer.testmail.deliver_later @@ -18,11 +19,11 @@ describe 'expected usage' do it 'matches' do - expect(worker).to have_enqueued_job 'string', 1, true + expect(worker).to have_enqueued_job *worker_args end it 'matches on the global Worker queue' do - expect(Sidekiq::Worker).to have_enqueued_job 'string', 1, true + expect(Sidekiq::Worker).to have_enqueued_job *worker_args end it 'matches on an enqueued ActiveJob' do @@ -59,13 +60,13 @@ describe '#description' do it 'returns description' do - expect(argument_subject.description).to eq "have an enqueued #{worker} job with arguments [\"string\", 1, true]" + expect(argument_subject.description).to eq "have an enqueued #{worker} job with arguments [\"string\", 1, true, {\"key\"=>\"value\", \"nested\"=>[{\"hash\"=>true}]}]" end end describe '#failure_message' do it 'returns message' do - expect(argument_subject.failure_message).to eq "expected to have an enqueued #{worker} job with arguments [\"string\", 1, true]\n\nfound: [[\"string\", 1, true]]" + expect(argument_subject.failure_message).to eq "expected to have an enqueued #{worker} job with arguments [\"string\", 1, true, {\"key\"=>\"value\", \"nested\"=>[{\"hash\"=>true}]}]\n\nfound: [[\"string\", 1, true, {\"key\"=>\"value\", \"nested\"=>[{\"hash\"=>true}]}]]" end end @@ -103,7 +104,7 @@ describe '#failure_message_when_negated' do it 'returns message' do - expect(argument_subject.failure_message_when_negated).to eq "expected to not have an enqueued #{worker} job with arguments [\"string\", 1, true]" + expect(argument_subject.failure_message_when_negated).to eq "expected to not have an enqueued #{worker} job with arguments [\"string\", 1, true, {\"key\"=>\"value\", \"nested\"=>[{\"hash\"=>true}]}]" end end end diff --git a/spec/rspec/sidekiq/version_spec.rb b/spec/rspec/sidekiq/version_spec.rb index e0567ca..b406aa2 100644 --- a/spec/rspec/sidekiq/version_spec.rb +++ b/spec/rspec/sidekiq/version_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' RSpec.describe RSpec::Sidekiq::VERSION do - it { is_expected.to eq('2.1.0') } + it { is_expected.to eq('2.2.0') } end