rspec-sidekiq 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76cd53af3be89c34df72acb829234afa380827dc
4
- data.tar.gz: f7f2fbaa2586f84587592824df13dab2fc783523
3
+ metadata.gz: c3bfc0f5fbded94f5135119b53c455ff09156e70
4
+ data.tar.gz: 4401a55dbbfc4da0e0fd47a0b096fe91bf78cd92
5
5
  SHA512:
6
- metadata.gz: 5ebf9b0763ade30bc300c29149e030b2d28cfeb0cb8d59365bcb5fa9b3de76bd32b8a1c5d40829f3e431f120250d566e6e1085676c01ed0dcc4040f7bab8a4ec
7
- data.tar.gz: 4e5a37a9b4347167304d6397099ad2b0cfa0db852be3d46fb27c8d1b31c1905ab72073929bb30d7f1a6e13dafbbe891fc6be35e1dab965ca6a19789abc785ddd
6
+ metadata.gz: 226211091e343370183a1f9c4ee031431be35259315e455686bd27aa015f9e293677105a4636e48fd56c591b33d84ebb93b2bf30faa2f284651cb7455d128a90
7
+ data.tar.gz: c0432c59598027cf1c2647c5a7ed4259ed090c109710bd7d1230fece72e92b9c5c05f362e59bcbe3df91a9a266f768ea3e11aba23857a3ac2dbcc7d361f6dcb5
data/.simplecov CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  SimpleCov.start do
3
2
  add_filter '/spec/'
4
3
 
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ 2.1.0
2
+ ---
3
+ * ActiveJob support [tarzan#71]
4
+ * adding be expired in matcher [bernabas#72]
5
+ * Fixed testing failures with be_delayed matcher due to rename of `enqueued_at` to `created_at` in latest Sidekiq [philostler]
6
+ * Add support for NullBatch#on and NullStatus#failures to the null batch objects. [PacerPRO#64]
7
+ * Adding a save_backtrace matcher [webdestroya#61]
8
+ * Add flag to skip Batch stubs [paulfri#69]
9
+ * allow passing an instance method to be_delayed matcher [lastobelus#63]
10
+
1
11
  2.0.0
2
12
  ---
3
13
  * Get specs to green [petergoldstein#58]
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Phil Ostler
3
+ Copyright (c) 2014, 2015 Phil Ostler
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
data/README.md CHANGED
@@ -69,6 +69,10 @@ Object.delay_until(1.hour.from_now).is_nil? # delay until
69
69
  expect(Object.method :is_nil?).to be_delayed.until 1.hour.from_now
70
70
  Object.delay_until(1.hour.from_now).is_a? Object # delay until with argument
71
71
  expect(Object.method :is_a?).to be_delayed(Object).until 1.hour.from_now
72
+
73
+ #Rails Mailer
74
+ MyMailer.delay.some_mail
75
+ expect(MyMailer.instance_method :some_mail).to be_delayed
72
76
  ```
73
77
 
74
78
  ### be_processed_in
@@ -95,6 +99,23 @@ expect(AwesomeJob).to be_retryable false # or
95
99
  it { is_expected.to be_retryable false }
96
100
  ```
97
101
 
102
+ ### save_backtrace
103
+ *Describes if a job should save the error backtrace when there is a failure in it's execution*
104
+ ```ruby
105
+ sidekiq_options backtrace: 5
106
+ # test with...
107
+ expect(AwesomeJob).to save_backtrace # or
108
+ it { is_expected.to save_backtrace }
109
+ # ...or alternatively specifiy the number of lines that should be saved
110
+ expect(AwesomeJob).to save_backtrace 5 # or
111
+ it { is_expected.to save_backtrace 5 }
112
+ # ...or when it should not save the backtrace
113
+ expect(AwesomeJob).to_not save_backtrace # or
114
+ expect(AwesomeJob).to save_backtrace false # or
115
+ it { is_expected.to_not save_backtrace } # or
116
+ it { is_expected.to save_backtrace false }
117
+ ```
118
+
98
119
  ### be_unique
99
120
  *Describes when a job should be unique within it's queue*
100
121
  ```ruby
@@ -103,6 +124,14 @@ sidekiq_options unique: true
103
124
  expect(AwesomeJob).to be_unique
104
125
  it { is_expected.to be_unique }
105
126
  ```
127
+ ### be_expired_in
128
+ *Describes when a job should expire*
129
+ ```ruby
130
+ sidekiq_options expires_in: 1.hour
131
+ # test with...
132
+ it { is_expected.to be_expired_in 1.hour }
133
+ it { is_expected.to_not be_expired_in 2.hours }
134
+ ```
106
135
 
107
136
  ### have_enqueued_job
108
137
  *Describes that there should be an enqueued job with the specified arguments*
@@ -120,6 +149,7 @@ describe AwesomeJob do
120
149
  it { is_expected.to be_processed_in :my_queue }
121
150
  it { is_expected.to be_retryable 5 }
122
151
  it { is_expected.to be_unique }
152
+ it { is_expected.to be_expired_in 1.hour }
123
153
 
124
154
  it 'enqueues another awesome job' do
125
155
  subject.perform
@@ -14,10 +14,15 @@ if defined? Sidekiq::Batch
14
14
 
15
15
  def initialize(bid = nil)
16
16
  @bid = bid || SecureRandom.hex(8)
17
+ @callbacks = []
17
18
  end
18
19
 
19
20
  def status
20
- NullStatus.new(@bid)
21
+ NullStatus.new(@bid, @callbacks)
22
+ end
23
+
24
+ def on(*args)
25
+ @callbacks << args
21
26
  end
22
27
 
23
28
  def jobs(*)
@@ -28,12 +33,23 @@ if defined? Sidekiq::Batch
28
33
  class NullStatus < NullObject
29
34
  attr_reader :bid
30
35
 
31
- def initialize(bid)
36
+ def initialize(bid, callbacks)
32
37
  @bid = bid
38
+ @callbacks = callbacks
39
+ end
40
+
41
+ def failures
42
+ 0
33
43
  end
34
44
 
35
45
  def join
36
46
  ::Sidekiq::Worker.drain_all
47
+
48
+ @callbacks.each do |event, callback_class, options|
49
+ if event != :success || failures == 0
50
+ callback_class.new.send("on_#{event}", self, options)
51
+ end
52
+ end
37
53
  end
38
54
 
39
55
  def total
@@ -44,7 +60,9 @@ if defined? Sidekiq::Batch
44
60
  end
45
61
 
46
62
  RSpec.configure do |config|
47
- config.before(:each) do
63
+ config.before(:each) do |example|
64
+ next if example.metadata[:stub_batches] == false
65
+
48
66
  if mocked_with_mocha?
49
67
  Sidekiq::Batch.stubs(:new) { RSpec::Sidekiq::NullBatch.new }
50
68
  else
@@ -1,9 +1,11 @@
1
1
  require 'rspec/core'
2
2
  require 'rspec/sidekiq/matchers/be_delayed'
3
+ require 'rspec/sidekiq/matchers/be_expired_in'
3
4
  require 'rspec/sidekiq/matchers/be_processed_in'
4
5
  require 'rspec/sidekiq/matchers/be_retryable'
5
6
  require 'rspec/sidekiq/matchers/be_unique'
6
7
  require 'rspec/sidekiq/matchers/have_enqueued_job'
8
+ require 'rspec/sidekiq/matchers/save_backtrace'
7
9
 
8
10
  RSpec.configure do |config|
9
11
  config.include RSpec::Sidekiq::Matchers
@@ -19,7 +19,7 @@ module RSpec
19
19
  end
20
20
 
21
21
  def failure_message
22
- "expected #{@expected_method.receiver}.#{@expected_method.name} to " + description
22
+ "expected #{@expected_method_receiver}.#{@expected_method.name} to " + description
23
23
  end
24
24
 
25
25
  def for(interval)
@@ -29,10 +29,12 @@ module RSpec
29
29
 
30
30
  def matches?(expected_method)
31
31
  @expected_method = expected_method
32
+ @expected_method_receiver = @expected_method.is_a?(UnboundMethod) ? @expected_method.owner : @expected_method.receiver
32
33
 
33
34
  find_job @expected_method, @expected_arguments do |job|
34
35
  if @expected_interval
35
- return job['at'].to_i == job['enqueued_at'].to_i + @expected_interval
36
+ created_enqueued_at = job['enqueued_at'] || job['created_at']
37
+ return job['at'].to_i == created_enqueued_at.to_i + @expected_interval
36
38
  elsif @expected_time
37
39
  return job['at'].to_i == @expected_time.to_i
38
40
  else
@@ -44,7 +46,7 @@ module RSpec
44
46
  end
45
47
 
46
48
  def failure_message_when_negated
47
- "expected #{@expected_method.receiver}.#{@expected_method.name} to not " + description
49
+ "expected #{@expected_method_receiver}.#{@expected_method.name} to not " + description
48
50
  end
49
51
 
50
52
  def until(time)
@@ -57,7 +59,7 @@ module RSpec
57
59
  def find_job(method, arguments, &block)
58
60
  job = (::Sidekiq::Extensions::DelayedClass.jobs + ::Sidekiq::Extensions::DelayedModel.jobs + ::Sidekiq::Extensions::DelayedMailer.jobs).find do |job|
59
61
  yaml = YAML.load(job['args'].first)
60
- @expected_method.receiver == yaml[0] && @expected_method.name == yaml[1] && (@expected_arguments <=> yaml[2]) == 0
62
+ @expected_method_receiver == yaml[0] && @expected_method.name == yaml[1] && (@expected_arguments <=> yaml[2]) == 0
61
63
  end
62
64
 
63
65
  yield job if block && job
@@ -0,0 +1,33 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def be_expired_in(expected_argument)
5
+ BeExpiredIn.new(expected_argument)
6
+ end
7
+
8
+ class BeExpiredIn
9
+ def initialize(expected_argument)
10
+ @expected_argument = expected_argument
11
+ end
12
+
13
+ def description
14
+ "to expire in #{@expected_argument}"
15
+ end
16
+
17
+ def failure_message
18
+ "expected to expire in #{@expected_argument} but expired in #{@actual}"
19
+ end
20
+
21
+ def failure_message_when_negated
22
+ "expected to not expire in #{@expected_argument}"
23
+ end
24
+
25
+ def matches?(job)
26
+ @klass = job.is_a?(Class) ? job : job.class
27
+ @actual = @klass.get_sidekiq_options['expires_in']
28
+ @actual.to_s == @expected_argument.to_s
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -20,7 +20,11 @@ module RSpec
20
20
 
21
21
  def matches?(job)
22
22
  @klass = job.is_a?(Class) ? job : job.class
23
- @actual = @klass.get_sidekiq_options['queue']
23
+ if @klass.methods.include?(:get_sidekiq_options)
24
+ @actual = @klass.get_sidekiq_options['queue']
25
+ else
26
+ @actual = job.try(:queue_name)
27
+ end
24
28
  @actual.to_s == @expected_queue.to_s
25
29
  end
26
30
 
@@ -23,7 +23,7 @@ module RSpec
23
23
 
24
24
  def matches?(klass)
25
25
  @klass = klass
26
- @actual = klass.jobs.map { |job| job['args'] }
26
+ @actual = unwrapped_job_arguments(klass.jobs)
27
27
  @actual.any? { |arguments| contain_exactly?(arguments) }
28
28
  end
29
29
 
@@ -33,6 +33,29 @@ module RSpec
33
33
 
34
34
  private
35
35
 
36
+ def unwrapped_job_arguments(jobs)
37
+ if jobs.is_a? Hash
38
+ jobs.values.flatten.map do |job|
39
+ map_arguments(job).flatten
40
+ end
41
+ else
42
+ map_arguments(jobs)
43
+ end
44
+ end
45
+
46
+ def map_arguments(job)
47
+ args = job_arguments(job) || job
48
+ if args.respond_to?(:any?) && args.any? { |e| e.is_a? Hash }
49
+ args.map { |a| map_arguments(a) }
50
+ else
51
+ args
52
+ end
53
+ end
54
+
55
+ def job_arguments(hash)
56
+ hash['arguments'] || hash['args'] unless hash.is_a? Array
57
+ end
58
+
36
59
  def contain_exactly?(arguments)
37
60
  exactly = RSpec::Matchers::BuiltIn::ContainExactly.new(expected_arguments)
38
61
  exactly.matches?(arguments)
@@ -0,0 +1,39 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def save_backtrace(expected_backtrace=true)
5
+ SaveBacktrace.new expected_backtrace
6
+ end
7
+
8
+ class SaveBacktrace
9
+ def initialize(expected_backtrace=true)
10
+ @expected_backtrace = expected_backtrace
11
+ end
12
+
13
+ def description
14
+ if @expected_backtrace.is_a?(Fixnum)
15
+ "save #{@expected_backtrace} lines of error backtrace" # backtrace: 5
16
+ elsif @expected_backtrace
17
+ 'save error backtrace' # backtrace: true
18
+ else
19
+ 'not save error backtrace' # backtrace: false
20
+ end
21
+ end
22
+
23
+ def failure_message
24
+ "expected #{@klass} to #{description} but got #{@actual}"
25
+ end
26
+
27
+ def matches?(job)
28
+ @klass = job.is_a?(Class) ? job : job.class
29
+ @actual = @klass.get_sidekiq_options['backtrace']
30
+ @actual == @expected_backtrace
31
+ end
32
+
33
+ def failure_message_when_negated
34
+ "expected #{@klass} to not #{description}".gsub 'not not ', ''
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Sidekiq
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require File.expand_path('../lib/rspec/sidekiq/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |s|
@@ -15,8 +14,11 @@ Gem::Specification.new do |s|
15
14
  s.add_dependency 'rspec', '~> 3.0', '>= 3.0.0'
16
15
  s.add_dependency 'sidekiq', '>= 2.4.0'
17
16
 
18
- s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.0'
17
+ s.add_development_dependency 'coveralls', '~> 0.8', '>= 0.8.0'
19
18
  s.add_development_dependency 'fuubar', '~> 2.0', '>= 2.0.0'
19
+ s.add_development_dependency 'activejob', '~> 4.2', '>= 4.0.0'
20
+ s.add_development_dependency 'actionmailer', '~> 4.2', '>= 4.0.0'
21
+
20
22
 
21
23
  s.files = Dir['.gitattributes'] +
22
24
  Dir['.gitignore'] +
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RSpec::Sidekiq::Matchers::BeExpiredIn do
4
+ let(:subject) { RSpec::Sidekiq::Matchers::BeExpiredIn.new 1 }
5
+ let(:worker) { create_worker expires_in: 1 }
6
+
7
+ describe '#be_expired_in' do
8
+ it 'returns instance' do
9
+ expect(be_expired_in 1).to be_a RSpec::Sidekiq::Matchers::BeExpiredIn
10
+ end
11
+ end
12
+
13
+ describe 'expected usage' do
14
+ it 'matches' do
15
+ expect(worker).to be_expired_in 1
16
+ end
17
+
18
+ context 'with negated' do
19
+ it 'matches' do
20
+ expect(worker).to_not be_expired_in 2
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#failure_message' do
26
+ it 'returns message' do
27
+ subject.matches? worker
28
+ expect(subject.failure_message).to eq "expected to expire in #{worker.sidekiq_options['expires_in']} but expired in #{subject.instance_variable_get(:@expected_argument)}"
29
+ end
30
+ end
31
+
32
+ describe '#matches?' do
33
+ context 'when expected equals actual' do
34
+ it 'returns true' do
35
+ expect(subject.matches? worker).to be true
36
+ end
37
+ end
38
+ context 'when expected is not equal to actual' do
39
+ it 'returns false' do
40
+ expect(RSpec::Sidekiq::Matchers::BeExpiredIn.new(2).matches? worker). to be false
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#failure_message_when_negated' do
46
+ it 'returns message' do
47
+ subject.matches? worker
48
+ expect(subject.failure_message_when_negated).to eq "expected to not expire in #{subject.instance_variable_get(:@expected_argument)}"
49
+ end
50
+ end
51
+
52
+ describe '#description' do
53
+ it 'returns message' do
54
+ expect(subject.description).to eq "to expire in #{subject.instance_variable_get(:@expected_argument)}"
55
+ end
56
+ end
57
+ end
@@ -5,6 +5,8 @@ RSpec.describe RSpec::Sidekiq::Matchers::BeProcessedIn do
5
5
  let(:symbol_worker) { create_worker queue: :a_queue }
6
6
  let(:string_subject) { RSpec::Sidekiq::Matchers::BeProcessedIn.new 'a_queue' }
7
7
  let(:string_worker) { create_worker queue: 'a_queue' }
8
+ let(:active_job) { create_active_job :mailers }
9
+
8
10
  before(:each) do
9
11
  symbol_subject.matches? symbol_worker
10
12
  string_subject.matches? string_worker
@@ -14,6 +16,10 @@ RSpec.describe RSpec::Sidekiq::Matchers::BeProcessedIn do
14
16
  it 'matches' do
15
17
  expect(symbol_worker).to be_processed_in :a_queue
16
18
  end
19
+
20
+ it 'matches on an ActiveJob' do
21
+ expect(active_job).to be_processed_in :mailers
22
+ end
17
23
  end
18
24
 
19
25
  describe '#be_processed_in' do
@@ -4,8 +4,15 @@ RSpec.describe RSpec::Sidekiq::Matchers::HaveEnqueuedJob do
4
4
  let(:argument_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new ['string', 1, true] }
5
5
  let(:matcher_subject) { RSpec::Sidekiq::Matchers::HaveEnqueuedJob.new [be_a(String), be_a(Fixnum), true] }
6
6
  let(:worker) { create_worker }
7
+ let(:active_job) { create_active_job :mailers }
8
+ let(:resource) { TestResource.new }
9
+
7
10
  before(:each) do
8
11
  worker.perform_async 'string', 1, true
12
+ active_job.perform_later 'someResource'
13
+ active_job.perform_later(resource)
14
+ TestActionMailer.testmail.deliver_later
15
+ TestActionMailer.testmail(resource).deliver_later
9
16
  argument_subject.matches? worker
10
17
  end
11
18
 
@@ -13,6 +20,35 @@ RSpec.describe RSpec::Sidekiq::Matchers::HaveEnqueuedJob do
13
20
  it 'matches' do
14
21
  expect(worker).to have_enqueued_job 'string', 1, true
15
22
  end
23
+
24
+ it 'matches on the global Worker queue' do
25
+ expect(Sidekiq::Worker).to have_enqueued_job 'string', 1, true
26
+ end
27
+
28
+ it 'matches on an enqueued ActiveJob' do
29
+ expect(Sidekiq::Worker).to have_enqueued_job 'someResource'
30
+ end
31
+
32
+ it 'matches on an enqueued ActiveJob by global_id' do
33
+ expect(Sidekiq::Worker).to have_enqueued_job("_aj_globalid" => resource.to_global_id.uri.to_s)
34
+ end
35
+
36
+ it 'matches on ActionMailer Job' do
37
+ expect(Sidekiq::Worker).to have_enqueued_job(
38
+ "TestActionMailer",
39
+ "testmail",
40
+ "deliver_now"
41
+ )
42
+ end
43
+
44
+ it 'matches on ActionMailer with a resource Job' do
45
+ expect(Sidekiq::Worker).to have_enqueued_job(
46
+ "TestActionMailer",
47
+ "testmail",
48
+ "deliver_now",
49
+ { "_aj_globalid" => resource.to_global_id.uri.to_s }
50
+ )
51
+ end
16
52
  end
17
53
 
18
54
  describe '#have_enqueued_job' do
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RSpec::Sidekiq::Matchers::SaveBacktrace do
4
+ let(:specific_subject) { RSpec::Sidekiq::Matchers::SaveBacktrace.new 2 }
5
+ let(:specific_worker) { create_worker backtrace: 2 }
6
+ let(:default_subject) { RSpec::Sidekiq::Matchers::SaveBacktrace.new true }
7
+ let(:default_worker) { create_worker backtrace: true }
8
+ let(:negative_subject) { RSpec::Sidekiq::Matchers::SaveBacktrace.new false }
9
+ let(:negative_worker) { create_worker backtrace: false }
10
+ before(:each) do
11
+ specific_subject.matches? specific_worker
12
+ default_subject.matches? default_worker
13
+ negative_subject.matches? negative_worker
14
+ end
15
+
16
+ describe 'expected usage' do
17
+ it 'matches' do
18
+ expect(default_worker).to save_backtrace true
19
+ expect(default_worker).to save_backtrace
20
+ end
21
+
22
+ it 'negative usage' do
23
+ expect(negative_worker).to save_backtrace false
24
+ expect(negative_worker).to_not save_backtrace
25
+ end
26
+ end
27
+
28
+ describe '#save_backtrace' do
29
+ it 'returns instance' do
30
+ expect(save_backtrace true).to be_a RSpec::Sidekiq::Matchers::SaveBacktrace
31
+ expect(save_backtrace).to be_a RSpec::Sidekiq::Matchers::SaveBacktrace
32
+ end
33
+ end
34
+
35
+ describe '#description' do
36
+ context 'when expected is a number' do
37
+ it 'returns description' do
38
+ expect(specific_subject.description).to eq 'save 2 lines of error backtrace'
39
+ end
40
+ end
41
+
42
+ context 'when expected is true' do
43
+ it 'returns description' do
44
+ expect(default_subject.description).to eq 'save error backtrace'
45
+ end
46
+ end
47
+
48
+ context 'when expected is false' do
49
+ it 'returns description' do
50
+ expect(negative_subject.description).to eq 'not save error backtrace'
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#failure_message' do
56
+ context 'when expected is a number' do
57
+ it 'returns message' do
58
+ expect(specific_subject.failure_message).to eq "expected #{specific_worker} to save 2 lines of error backtrace but got 2"
59
+ end
60
+ end
61
+
62
+ context 'when expected is true' do
63
+ it 'returns message' do
64
+ expect(default_subject.failure_message).to eq "expected #{default_worker} to save error backtrace but got true"
65
+ end
66
+ end
67
+
68
+ context 'when expected is false' do
69
+ it 'returns message' do
70
+ expect(negative_subject.failure_message).to eq "expected #{negative_worker} to not save error backtrace but got false"
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#matches?' do
76
+ context 'when condition matches' do
77
+ context 'when expected is a number' do
78
+ it 'returns true' do
79
+ expect(specific_subject.matches? specific_worker).to be true
80
+ end
81
+ end
82
+
83
+ context 'when expected is true' do
84
+ it 'returns true' do
85
+ expect(default_subject.matches? default_worker).to be true
86
+ end
87
+ end
88
+
89
+ context 'when expected is false' do
90
+ it 'returns true' do
91
+ expect(negative_subject.matches? negative_worker).to be true
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'when condition does not match' do
97
+ context 'when expected is a number' do
98
+ it 'returns false' do
99
+ expect(specific_subject.matches? default_worker).to be false
100
+ end
101
+ end
102
+
103
+ context 'when expected is true' do
104
+ it 'returns false' do
105
+ expect(default_subject.matches? negative_worker).to be false
106
+ end
107
+ end
108
+
109
+ context 'when expected is false' do
110
+ it 'returns false' do
111
+ expect(negative_subject.matches? specific_worker).to be false
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '#failure_message_when_negated' do
118
+ context 'when expected is a number' do
119
+ it 'returns message' do
120
+ expect(specific_subject.failure_message_when_negated).to eq "expected #{specific_worker} to not save 2 lines of error backtrace"
121
+ end
122
+ end
123
+
124
+ context 'when expected is true' do
125
+ it 'returns message' do
126
+ expect(default_subject.failure_message_when_negated).to eq "expected #{default_worker} to not save error backtrace"
127
+ end
128
+ end
129
+
130
+ context 'when expected is false' do
131
+ it 'returns message' do
132
+ expect(negative_subject.failure_message_when_negated).to eq "expected #{negative_worker} to save error backtrace"
133
+ end
134
+ end
135
+ end
136
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RSpec::Sidekiq::VERSION do
4
- it { is_expected.to eq('2.0.0') }
4
+ it { is_expected.to eq('2.1.0') }
5
5
  end
@@ -4,6 +4,9 @@ require 'coveralls'
4
4
  require 'sidekiq'
5
5
  require 'rspec-sidekiq'
6
6
 
7
+ require 'active_job'
8
+ require 'action_mailer'
9
+
7
10
  require_relative 'support/init'
8
11
 
9
12
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
@@ -17,3 +20,5 @@ RSpec.configure do |config|
17
20
 
18
21
  config.include RSpec::Sidekiq::Spec::Support::Factories
19
22
  end
23
+
24
+ ActiveJob::Base.queue_adapter = :sidekiq
@@ -15,6 +15,17 @@ module RSpec
15
15
  end
16
16
  Object.const_set clazz_name, clazz
17
17
  end
18
+
19
+ def create_active_job(options = {})
20
+ clazz_name = "ActiveJob#{ rand(36**10).to_s 36 }"
21
+ clazz = Class.new(ActiveJob::Base) do
22
+ queue_as options
23
+
24
+ def perform
25
+ end
26
+ end
27
+ Object.const_set clazz_name, clazz
28
+ end
18
29
  end
19
30
  end
20
31
  end
@@ -1,3 +1,6 @@
1
1
  require_relative 'factories'
2
2
  require_relative 'test_worker'
3
3
  require_relative 'test_worker_alternative'
4
+ require_relative 'test_job'
5
+ require_relative 'test_resource'
6
+ require_relative 'test_action_mailer'
@@ -0,0 +1,6 @@
1
+ class TestActionMailer < ActionMailer::Base
2
+ def testmail(resource = nil)
3
+ @resource = resource
4
+ mail(to: 'none@example.com', subject: 'testmail')
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class TestJob < ActiveJob::Base
2
+ queue_as :mailers
3
+
4
+ def perform
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ class TestResource
2
+ include GlobalID::Identification
3
+
4
+ attr_reader :global_id
5
+
6
+ def initialize
7
+ @global_id = GlobalID.create(self, { app: 'rspec-sidekiq' })
8
+ end
9
+
10
+ def self.find(id)
11
+ end
12
+
13
+ def id
14
+ rand(36**10).to_s 36
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Ostler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -50,20 +50,20 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.7'
53
+ version: '0.8'
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.7.0
56
+ version: 0.8.0
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '0.7'
63
+ version: '0.8'
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 0.7.0
66
+ version: 0.8.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: fuubar
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +84,46 @@ dependencies:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 2.0.0
87
+ - !ruby/object:Gem::Dependency
88
+ name: activejob
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '4.2'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 4.0.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 4.0.0
107
+ - !ruby/object:Gem::Dependency
108
+ name: actionmailer
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '4.2'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 4.0.0
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '4.2'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 4.0.0
87
127
  description: Simple testing of Sidekiq jobs via a collection of matchers and helpers
88
128
  email: github@philostler.com
89
129
  executables: []
@@ -105,25 +145,32 @@ files:
105
145
  - lib/rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block.rb
106
146
  - lib/rspec/sidekiq/matchers.rb
107
147
  - lib/rspec/sidekiq/matchers/be_delayed.rb
148
+ - lib/rspec/sidekiq/matchers/be_expired_in.rb
108
149
  - lib/rspec/sidekiq/matchers/be_processed_in.rb
109
150
  - lib/rspec/sidekiq/matchers/be_retryable.rb
110
151
  - lib/rspec/sidekiq/matchers/be_unique.rb
111
152
  - lib/rspec/sidekiq/matchers/have_enqueued_job.rb
153
+ - lib/rspec/sidekiq/matchers/save_backtrace.rb
112
154
  - lib/rspec/sidekiq/sidekiq.rb
113
155
  - lib/rspec/sidekiq/version.rb
114
156
  - rspec-sidekiq.gemspec
115
157
  - spec/rspec/sidekiq/batch_spec.rb
116
158
  - spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb
117
159
  - spec/rspec/sidekiq/matchers/be_delayed_spec.rb
160
+ - spec/rspec/sidekiq/matchers/be_expired_in_spec.rb
118
161
  - spec/rspec/sidekiq/matchers/be_processed_in_spec.rb
119
162
  - spec/rspec/sidekiq/matchers/be_retryable_spec.rb
120
163
  - spec/rspec/sidekiq/matchers/be_unique_spec.rb
121
164
  - spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb
165
+ - spec/rspec/sidekiq/matchers/save_backtrace_spec.rb
122
166
  - spec/rspec/sidekiq/sidekiq_spec.rb
123
167
  - spec/rspec/sidekiq/version_spec.rb
124
168
  - spec/spec_helper.rb
125
169
  - spec/support/factories.rb
126
170
  - spec/support/init.rb
171
+ - spec/support/test_action_mailer.rb
172
+ - spec/support/test_job.rb
173
+ - spec/support/test_resource.rb
127
174
  - spec/support/test_worker.rb
128
175
  - spec/support/test_worker_alternative.rb
129
176
  homepage: http://github.com/philostler/rspec-sidekiq
@@ -146,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
193
  version: '0'
147
194
  requirements: []
148
195
  rubyforge_project:
149
- rubygems_version: 2.2.2
196
+ rubygems_version: 2.4.6
150
197
  signing_key:
151
198
  specification_version: 4
152
199
  summary: RSpec for Sidekiq