diff --git a/lib/rspec/sidekiq/batch.rb b/lib/rspec/sidekiq/batch.rb index 94d8445..9f6a6c5 100644 --- a/lib/rspec/sidekiq/batch.rb +++ b/lib/rspec/sidekiq/batch.rb @@ -34,8 +34,8 @@ def total Sidekiq::Batch.stubs(:new) { RSpec::Sidekiq::NullBatch.new } Sidekiq::Batch::Status.stubs(:new) { RSpec::Sidekiq::NullStatus.new } else - Sidekiq::Batch.stub(:new) { RSpec::Sidekiq::NullBatch.new } - Sidekiq::Batch::Status.stub(:new) { RSpec::Sidekiq::NullStatus.new } + allow(Sidekiq::Batch).to receive(:new) { RSpec::Sidekiq::NullBatch.new } + allow(Sidekiq::Batch::Status).to receive(:new) { RSpec::Sidekiq::NullStatus.new } end end end diff --git a/lib/rspec/sidekiq/matchers/be_delayed.rb b/lib/rspec/sidekiq/matchers/be_delayed.rb index 42a57e1..a74afe4 100644 --- a/lib/rspec/sidekiq/matchers/be_delayed.rb +++ b/lib/rspec/sidekiq/matchers/be_delayed.rb @@ -43,7 +43,7 @@ def matches? expected_method return false end - def negative_failure_message + def failure_message_when_negated "expected #{@expected_method.receiver}.#{@expected_method.name} to not " + description end diff --git a/lib/rspec/sidekiq/matchers/be_processed_in.rb b/lib/rspec/sidekiq/matchers/be_processed_in.rb index ed39764..ac780fb 100644 --- a/lib/rspec/sidekiq/matchers/be_processed_in.rb +++ b/lib/rspec/sidekiq/matchers/be_processed_in.rb @@ -24,7 +24,7 @@ def matches? job @actual.to_s == @expected_queue.to_s end - def negative_failure_message + def failure_message_when_negated "expected #{@klass} to not be processed in the \"#{@expected_queue}\" queue" end end diff --git a/lib/rspec/sidekiq/matchers/be_retryable.rb b/lib/rspec/sidekiq/matchers/be_retryable.rb index a459bc7..9399c46 100644 --- a/lib/rspec/sidekiq/matchers/be_retryable.rb +++ b/lib/rspec/sidekiq/matchers/be_retryable.rb @@ -30,7 +30,7 @@ def matches? job @actual == @expected_retry end - def negative_failure_message + def failure_message_when_negated "expected #{@klass} to not #{description}".gsub "not not ", "" end end diff --git a/lib/rspec/sidekiq/matchers/be_unique.rb b/lib/rspec/sidekiq/matchers/be_unique.rb index 48e1fe4..239a2c9 100644 --- a/lib/rspec/sidekiq/matchers/be_unique.rb +++ b/lib/rspec/sidekiq/matchers/be_unique.rb @@ -20,7 +20,7 @@ def matches? job @actual == true end - def negative_failure_message + def failure_message_when_negated "expected #{@klass} to not be unique in the queue" end end diff --git a/lib/rspec/sidekiq/matchers/have_enqueued_job.rb b/lib/rspec/sidekiq/matchers/have_enqueued_job.rb index 44e75fb..f9af935 100644 --- a/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +++ b/lib/rspec/sidekiq/matchers/have_enqueued_job.rb @@ -6,28 +6,39 @@ def have_enqueued_job *expected_arguments end class HaveEnqueuedJob - def initialize expected_arguments + + attr_reader :klass, :expected_arguments, :actual + + def initialize(expected_arguments) @expected_arguments = expected_arguments end def description - "have an enqueued #{@klass} job with arguments #{@expected_arguments}" + "have an enqueued #{klass} job with arguments #{expected_arguments}" end def failure_message - "expected to have an enqueued #{@klass} job with arguments #{@expected_arguments}\n\n" + - "found: #{@actual}" + "expected to have an enqueued #{klass} job with arguments #{expected_arguments}\n\n" + + "found: #{actual}" end - def matches? klass + def matches?(klass) @klass = klass @actual = klass.jobs.map { |job| job["args"] } - @actual.any? { |arguments| Array(@expected_arguments) == arguments } + @actual.any? { |arguments| contain_exactly?(arguments) } + end + + def failure_message_when_negated + "expected to not have an enqueued #{klass} job with arguments #{expected_arguments}" end - def negative_failure_message - "expected to not have an enqueued #{@klass} job with arguments #{@expected_arguments}" + private + + def contain_exactly?(arguments) + exactly = RSpec::Matchers::BuiltIn::ContainExactly.new(expected_arguments) + exactly.matches?(arguments) end + end end end diff --git a/rspec-sidekiq.gemspec b/rspec-sidekiq.gemspec index c575bcb..ed510c4 100644 --- a/rspec-sidekiq.gemspec +++ b/rspec-sidekiq.gemspec @@ -12,12 +12,12 @@ Gem::Specification.new do |s| s.description = "Simple testing of Sidekiq jobs via a collection of matchers and helpers" s.license = "MIT" - s.add_dependency "rspec", ">= 2.0.0" + s.add_dependency "rspec", ">= 3.0.0.beta2" s.add_dependency "sidekiq", ">= 2.4.0" s.add_development_dependency "coveralls", "~> 0.7.0" s.add_development_dependency "fuubar", ">= 1.1.0" - s.add_development_dependency "rspec", ">= 2.0.0" + s.add_development_dependency "rspec", ">= 3.0.0.beta2" s.add_development_dependency "sidekiq", ">= 2.4.0" s.files = Dir[".gitattributes"] + diff --git a/spec/rspec/sidekiq/matchers/be_delayed_spec.rb b/spec/rspec/sidekiq/matchers/be_delayed_spec.rb index a214cc2..d45d1a2 100644 --- a/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +++ b/spec/rspec/sidekiq/matchers/be_delayed_spec.rb @@ -198,40 +198,40 @@ end end - describe "#negative_failure_message" do + describe "#failure_message_when_negated" do context "when expected is a delay" do it "returns message" do - expect(delay_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed" + expect(delay_subject.failure_message_when_negated).to eq "expected Object.nil? to not be delayed" end end context "when expected is a delay with arguments" do it "returns message" do - expect(delay_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed with arguments [Object]" + expect(delay_with_arguments_subject.failure_message_when_negated).to eq "expected Object.is_a? to not be delayed with arguments [Object]" end end context "when expected is a delay for" do it "returns message" do - expect(delay_for_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed for 3600 seconds" + expect(delay_for_subject.failure_message_when_negated).to eq "expected Object.nil? to not be delayed for 3600 seconds" end end context "when expected is a delay for with arguments" do it "returns message" do - expect(delay_for_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed for 3600 seconds with arguments [Object]" + expect(delay_for_with_arguments_subject.failure_message_when_negated).to eq "expected Object.is_a? to not be delayed for 3600 seconds with arguments [Object]" end end context "when expected is a delay until" do it "returns message" do - expect(delay_until_subject.negative_failure_message).to eq "expected Object.nil? to not be delayed until #{Time.now + 3600}" + expect(delay_until_subject.failure_message_when_negated).to eq "expected Object.nil? to not be delayed until #{Time.now + 3600}" end end context "when expected is a delay until with arguments" do it "returns message" do - expect(delay_until_with_arguments_subject.negative_failure_message).to eq "expected Object.is_a? to not be delayed until #{Time.now + 3600} with arguments [Object]" + expect(delay_until_with_arguments_subject.failure_message_when_negated).to eq "expected Object.is_a? to not be delayed until #{Time.now + 3600} with arguments [Object]" end end end diff --git a/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb b/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb index 0bb86a9..9c0d79c 100644 --- a/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +++ b/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb @@ -92,16 +92,16 @@ end end - describe "#negative_failure_message" do + describe "#failure_message_when_negated" do context "when expected is a symbol" do it "returns message" do - expect(symbol_subject.negative_failure_message).to eq "expected #{symbol_worker} to not be processed in the \"a_queue\" queue" + expect(symbol_subject.failure_message_when_negated).to eq "expected #{symbol_worker} to not be processed in the \"a_queue\" queue" end end context "when expected is a string" do it "returns message" do - expect(string_subject.negative_failure_message).to eq "expected #{string_worker} to not be processed in the \"a_queue\" queue" + expect(string_subject.failure_message_when_negated).to eq "expected #{string_worker} to not be processed in the \"a_queue\" queue" end end end diff --git a/spec/rspec/sidekiq/matchers/be_retryable_spec.rb b/spec/rspec/sidekiq/matchers/be_retryable_spec.rb index 8a15d8f..80ce8b5 100644 --- a/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +++ b/spec/rspec/sidekiq/matchers/be_retryable_spec.rb @@ -107,22 +107,22 @@ end end - describe "#negative_failure_message" do + describe "#failure_message_when_negated" do context "when expected is a number" do it "returns message" do - expect(specific_subject.negative_failure_message).to eq "expected #{specific_worker} to not retry 2 times" + expect(specific_subject.failure_message_when_negated).to eq "expected #{specific_worker} to not retry 2 times" end end context "when expected is true" do it "returns message" do - expect(default_subject.negative_failure_message).to eq "expected #{default_worker} to not retry the default number of times" + expect(default_subject.failure_message_when_negated).to eq "expected #{default_worker} to not retry the default number of times" end end context "when expected is false" do it "returns message" do - expect(negative_subject.negative_failure_message).to eq "expected #{negative_worker} to retry" + expect(negative_subject.failure_message_when_negated).to eq "expected #{negative_worker} to retry" end end end diff --git a/spec/rspec/sidekiq/matchers/be_unique_spec.rb b/spec/rspec/sidekiq/matchers/be_unique_spec.rb index 9cfe319..47ded8f 100644 --- a/spec/rspec/sidekiq/matchers/be_unique_spec.rb +++ b/spec/rspec/sidekiq/matchers/be_unique_spec.rb @@ -42,9 +42,9 @@ end end - describe "#negative_failure_message" do + describe "#failure_message_when_negated" do it "returns message" do - expect(subject.negative_failure_message).to eq "expected #{worker} to not be unique in the queue" + expect(subject.failure_message_when_negated).to eq "expected #{worker} to not be unique in the queue" end end end \ No newline at end of file diff --git a/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb b/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb index 5599e8b..ed252fd 100644 --- a/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +++ b/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb @@ -2,7 +2,7 @@ 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 [an_instance_of(String), an_instance_of(Fixnum), true] } + let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [be_a(String), be_a(Fixnum), true] } let(:worker) { create_worker } before(:each) do worker.perform_async "string", 1, true @@ -65,9 +65,9 @@ end end - describe "#negative_failure_message" do + describe "#failure_message_when_negated" do it "returns message" do - expect(argument_subject.negative_failure_message).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]" end end end \ No newline at end of file