Skip to content

Commit

Permalink
change to "rspec", ">= 3.0.0.beta2"
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Farhi committed Mar 26, 2014
1 parent e674fbc commit ecf3d76
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/sidekiq/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_delayed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_processed_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_retryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions lib/rspec/sidekiq/matchers/have_enqueued_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rspec-sidekiq.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"] +
Expand Down
14 changes: 7 additions & 7 deletions spec/rspec/sidekiq/matchers/be_delayed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/sidekiq/matchers/be_processed_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/sidekiq/matchers/be_retryable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/sidekiq/matchers/be_unique_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit ecf3d76

Please sign in to comment.