Skip to content

Commit

Permalink
Merge branch 'release/v2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ostler committed Dec 22, 2015
2 parents 1574ebc + 522b6be commit 82634af
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
```
Expand Down
16 changes: 14 additions & 2 deletions lib/rspec/sidekiq/matchers/have_enqueued_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module RSpec
module Sidekiq
VERSION = '2.1.0'
VERSION = '2.2.0'
end
end
17 changes: 9 additions & 8 deletions spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/rspec/sidekiq/version_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 82634af

Please sign in to comment.