rspec-sidekiq 1.1.0 → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -1
  4. data/.simplecov +1 -1
  5. data/CHANGES.md +5 -0
  6. data/Gemfile +5 -5
  7. data/LICENSE +2 -2
  8. data/README.md +0 -4
  9. data/lib/rspec-sidekiq.rb +8 -7
  10. data/lib/rspec/sidekiq/batch.rb +4 -2
  11. data/lib/rspec/sidekiq/configuration.rb +2 -1
  12. data/lib/rspec/sidekiq/helpers.rb +3 -2
  13. data/lib/rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block.rb +5 -4
  14. data/lib/rspec/sidekiq/matchers.rb +8 -8
  15. data/lib/rspec/sidekiq/matchers/be_delayed.rb +1 -2
  16. data/lib/rspec/sidekiq/matchers/be_processed_in.rb +1 -2
  17. data/lib/rspec/sidekiq/matchers/be_retryable.rb +1 -2
  18. data/lib/rspec/sidekiq/matchers/be_unique.rb +1 -2
  19. data/lib/rspec/sidekiq/matchers/have_enqueued_job.rb +19 -9
  20. data/lib/rspec/sidekiq/sidekiq.rb +4 -3
  21. data/lib/rspec/sidekiq/version.rb +2 -1
  22. data/rspec-sidekiq.gemspec +25 -25
  23. data/spec/rspec/sidekiq/batch_spec.rb +10 -9
  24. data/spec/rspec/sidekiq/helpers/retries_exhausted_spec.rb +2 -2
  25. data/spec/rspec/sidekiq/matchers/be_delayed_spec.rb +87 -86
  26. data/spec/rspec/sidekiq/matchers/be_processed_in_spec.rb +42 -41
  27. data/spec/rspec/sidekiq/matchers/be_retryable_spec.rb +49 -48
  28. data/spec/rspec/sidekiq/matchers/be_unique_spec.rb +24 -23
  29. data/spec/rspec/sidekiq/matchers/have_enqueued_job_spec.rb +29 -28
  30. data/spec/rspec/sidekiq/sidekiq_spec.rb +8 -7
  31. data/spec/rspec/sidekiq/version_spec.rb +3 -2
  32. data/spec/spec_helper.rb +7 -6
  33. data/spec/support/factories.rb +4 -3
  34. data/spec/support/init.rb +4 -3
  35. data/spec/support/test_worker.rb +2 -1
  36. data/spec/support/test_worker_alternative.rb +3 -2
  37. metadata +23 -25
  38. data/lib/rspec/sidekiq/matchers/have_enqueued_jobs.rb +0 -12
  39. data/spec/rspec/sidekiq/matchers/have_enqueued_jobs_spec.rb +0 -9
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTM0OGMwZTYyZGY4NTFkOTU0MjlhNGMxZDUzYTJmMzI5N2MwNTE1Zg==
5
- data.tar.gz: !binary |-
6
- Yzc5YWUwMWYwN2VlNzc4ZDlmNDI2OWQyOWNlMjJhOWRjYWI4Y2Q4Mg==
2
+ SHA1:
3
+ metadata.gz: e07823fce83d1a7b7a549812ab5f596232cf5a31
4
+ data.tar.gz: e86beeb6f94c7ae2865bfbb0fbad4bab719b6dd6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTZkOWEyNzk2MTNhMzA4MzE5ZmE0MmE2MWU2NTQ5ZDJmMzcwYzZkOTViY2U3
10
- MTFkMDEwMWIzYjE3NTRkZTA4MzU2Mjc0ZDAxZGY2Y2ZlNjQ2NGQ4YjI0NGQ2
11
- M2FhYTg0MTg5YmU2YjQwYjQyMDI2M2NhZWUzZTM3ZmZiODY3Yzk=
12
- data.tar.gz: !binary |-
13
- YmZiOTNjOGYxMGFhOTdhZDlmNDZiMjI5NDVkOWQ0ZjMyNGViZDJmNzI5ZGI3
14
- ZmM1YmYxYjEwODRlYzIxZjk3MmE2OTkzNDc1ZWJjMGJhYjI4MmMwMDBlNGY3
15
- NzA5ODgzY2Y3ZTNhNTM0YmFkMWVjMWQ5ZGMyZDMxMmJlMDhkZDM=
6
+ metadata.gz: 22bd9129ac7853dda2f35e0950f3f4914b691b79571a3fde7958f26dcf87311e440dcd0333498435049161f8aac6c008b94e7d4e9874a4a5c636445ae4307609
7
+ data.tar.gz: 0002ff94652d3da4f4c6d567f262cec5a68cead531a245e0950522ab74f8c7001467df386e59acd5b0b7b3fdf2c61c907f649c6616950680ccc1a8f1c07b0060
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
1
  Gemfile.lock
2
- spec/result
2
+ tmp
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --colour
2
2
  --tty
3
3
  --format Fuubar
4
- --format html --out spec/result/index.html
4
+ --format html --out tmp/spec_result/index.html
data/.simplecov CHANGED
@@ -2,5 +2,5 @@
2
2
  SimpleCov.start do
3
3
  add_filter '/spec/'
4
4
 
5
- coverage_dir 'spec/result/coverage'
5
+ coverage_dir 'tmp/spec_coverage'
6
6
  end
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.0.0.beta
2
+ ---
3
+ * Add support for 3.0.0 [yelled3#47]
4
+ * Completely remove have_enqueued_jobs matcher [philostler#56]
5
+
1
6
  1.1.0
2
7
  ---
3
8
  * Added Support for RSpec 3 [TBAA#44]
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  platforms :rbx do
4
- gem "rubysl", "~> 2.0"
5
- gem "psych"
6
- gem "rubinius-developer_tools"
4
+ gem 'rubysl', '~> 2.0'
5
+ gem 'psych'
6
+ gem 'rubinius-developer_tools'
7
7
  end
8
8
 
9
- gemspec
9
+ gemspec
data/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013 Phil Ostler
3
+ Copyright (c) 2014 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
 
7
7
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -51,7 +51,6 @@ end
51
51
  * [be_retryable](#be_retryable)
52
52
  * [be_unique](#be_unique)
53
53
  * [have_enqueued_job](#have_enqueued_job)
54
- * ~~[have_enqueued_jobs](#have_enqueued_jobs)~~
55
54
 
56
55
  ### be_delayed
57
56
  *Describes a method that should be invoked asynchronously (See [Sidekiq Delayed Extensions][sidekiq_wiki_delayed_extensions])*
@@ -113,9 +112,6 @@ Awesomejob.perform_async "Awesome", true
113
112
  expect(AwesomeJob).to have_enqueued_job("Awesome", true)
114
113
  ```
115
114
 
116
- ### ~~have_enqueued_jobs~~
117
- *Removed. [See the FAQ & Troubleshooting Wiki page][rspec_sidekiq_wiki_faq_&_troubleshooting] for alternative and more information*
118
-
119
115
  ## Example matcher usage
120
116
  ```ruby
121
117
  require "spec_helper"
@@ -1,8 +1,9 @@
1
- require "sidekiq"
2
- require "sidekiq/testing"
1
+ # encoding: utf-8
2
+ require 'sidekiq'
3
+ require 'sidekiq/testing'
3
4
 
4
- require "rspec/sidekiq/batch"
5
- require "rspec/sidekiq/configuration"
6
- require "rspec/sidekiq/helpers"
7
- require "rspec/sidekiq/matchers"
8
- require "rspec/sidekiq/sidekiq"
5
+ require 'rspec/sidekiq/batch'
6
+ require 'rspec/sidekiq/configuration'
7
+ require 'rspec/sidekiq/helpers'
8
+ require 'rspec/sidekiq/matchers'
9
+ require 'rspec/sidekiq/sidekiq'
@@ -1,4 +1,5 @@
1
- require "rspec/core"
1
+ # encoding: utf-8
2
+ require 'rspec/core'
2
3
 
3
4
  if defined? Sidekiq::Batch
4
5
  module RSpec
@@ -48,7 +49,8 @@ if defined? Sidekiq::Batch
48
49
  if mocked_with_mocha?
49
50
  Sidekiq::Batch.stubs(:new) { RSpec::Sidekiq::NullBatch.new }
50
51
  else
51
- Sidekiq::Batch.stub(:new) { RSpec::Sidekiq::NullBatch.new }
52
+ allow(Sidekiq::Batch).to receive(:new) { RSpec::Sidekiq::NullBatch.new }
53
+ allow(Sidekiq::Batch::Status).to receive(:new) { RSpec::Sidekiq::NullStatus.new }
52
54
  end
53
55
  end
54
56
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module RSpec
2
3
  module Sidekiq
3
4
  class Configuration
@@ -10,4 +11,4 @@ module RSpec
10
11
  end
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -1,2 +1,3 @@
1
- require "rspec/core"
2
- require "rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block"
1
+ # encoding: utf-8
2
+ require 'rspec/core'
3
+ require 'rspec/sidekiq/helpers/within_sidekiq_retries_exhausted_block'
@@ -1,19 +1,20 @@
1
+ # encoding: utf-8
1
2
  module Sidekiq
2
3
  module Worker
3
4
  module ClassMethods
4
- def within_sidekiq_retries_exhausted_block user_msg = {}, &block
5
+ def within_sidekiq_retries_exhausted_block(user_msg = {}, &block)
5
6
  block.call
6
- self.sidekiq_retries_exhausted_block.call default_retries_exhausted_args.merge(user_msg)
7
+ sidekiq_retries_exhausted_block.call default_retries_exhausted_args.merge(user_msg)
7
8
  end
8
9
 
9
10
  def default_retries_exhausted_args
10
11
  {
11
12
  'queue' => get_sidekiq_options[:worker],
12
- 'class' => self.name,
13
+ 'class' => name,
13
14
  'args' => [],
14
15
  'error_message' => 'An error occured'
15
16
  }
16
17
  end
17
18
  end
18
19
  end
19
- end
20
+ end
@@ -1,11 +1,11 @@
1
- require "rspec/core"
2
- require "rspec/sidekiq/matchers/be_delayed"
3
- require "rspec/sidekiq/matchers/be_processed_in"
4
- require "rspec/sidekiq/matchers/be_retryable"
5
- require "rspec/sidekiq/matchers/be_unique"
6
- require "rspec/sidekiq/matchers/have_enqueued_job"
7
- require "rspec/sidekiq/matchers/have_enqueued_jobs"
1
+ # encoding: utf-8
2
+ require 'rspec/core'
3
+ require 'rspec/sidekiq/matchers/be_delayed'
4
+ require 'rspec/sidekiq/matchers/be_processed_in'
5
+ require 'rspec/sidekiq/matchers/be_retryable'
6
+ require 'rspec/sidekiq/matchers/be_unique'
7
+ require 'rspec/sidekiq/matchers/have_enqueued_job'
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.include RSpec::Sidekiq::Matchers
11
- end
11
+ end
@@ -43,10 +43,9 @@ module RSpec
43
43
  return false
44
44
  end
45
45
 
46
- def negative_failure_message
46
+ def failure_message_when_negated
47
47
  "expected #{@expected_method.receiver}.#{@expected_method.name} to not " + description
48
48
  end
49
- alias_method :failure_message_when_negated, :negative_failure_message
50
49
 
51
50
  def until time
52
51
  @expected_time = time
@@ -24,10 +24,9 @@ module RSpec
24
24
  @actual.to_s == @expected_queue.to_s
25
25
  end
26
26
 
27
- def negative_failure_message
27
+ def failure_message_when_negated
28
28
  "expected #{@klass} to not be processed in the \"#{@expected_queue}\" queue"
29
29
  end
30
- alias_method :failure_message_when_negated, :negative_failure_message
31
30
  end
32
31
  end
33
32
  end
@@ -30,10 +30,9 @@ module RSpec
30
30
  @actual == @expected_retry
31
31
  end
32
32
 
33
- def negative_failure_message
33
+ def failure_message_when_negated
34
34
  "expected #{@klass} to not #{description}".gsub "not not ", ""
35
35
  end
36
- alias_method :failure_message_when_negated, :negative_failure_message
37
36
  end
38
37
  end
39
38
  end
@@ -20,10 +20,9 @@ module RSpec
20
20
  [true, :all].include?(@actual)
21
21
  end
22
22
 
23
- def negative_failure_message
23
+ def failure_message_when_negated
24
24
  "expected #{@klass} to not be unique in the queue"
25
25
  end
26
- alias_method :failure_message_when_negated, :negative_failure_message
27
26
  end
28
27
  end
29
28
  end
@@ -6,29 +6,39 @@ module RSpec
6
6
  end
7
7
 
8
8
  class HaveEnqueuedJob
9
- def initialize expected_arguments
9
+
10
+ attr_reader :klass, :expected_arguments, :actual
11
+
12
+ def initialize(expected_arguments)
10
13
  @expected_arguments = expected_arguments
11
14
  end
12
15
 
13
16
  def description
14
- "have an enqueued #{@klass} job with arguments #{@expected_arguments}"
17
+ "have an enqueued #{klass} job with arguments #{expected_arguments}"
15
18
  end
16
19
 
17
20
  def failure_message
18
- "expected to have an enqueued #{@klass} job with arguments #{@expected_arguments}\n\n" +
19
- "found: #{@actual}"
21
+ "expected to have an enqueued #{klass} job with arguments #{expected_arguments}\n\n" +
22
+ "found: #{actual}"
20
23
  end
21
24
 
22
- def matches? klass
25
+ def matches?(klass)
23
26
  @klass = klass
24
27
  @actual = klass.jobs.map { |job| job["args"] }
25
- @actual.any? { |arguments| Array(@expected_arguments) == arguments }
28
+ @actual.any? { |arguments| contain_exactly?(arguments) }
29
+ end
30
+
31
+ def failure_message_when_negated
32
+ "expected to not have an enqueued #{klass} job with arguments #{expected_arguments}"
26
33
  end
27
34
 
28
- def negative_failure_message
29
- "expected to not have an enqueued #{@klass} job with arguments #{@expected_arguments}"
35
+ private
36
+
37
+ def contain_exactly?(arguments)
38
+ exactly = RSpec::Matchers::BuiltIn::ContainExactly.new(expected_arguments)
39
+ exactly.matches?(arguments)
30
40
  end
31
- alias_method :failure_message_when_negated, :negative_failure_message
41
+
32
42
  end
33
43
  end
34
44
  end
@@ -1,7 +1,8 @@
1
+ # encoding: utf-8
1
2
  module RSpec
2
3
  module Sidekiq
3
4
  class << self
4
- def configure &block
5
+ def configure(&block)
5
6
  yield configuration if block
6
7
  end
7
8
 
@@ -14,7 +15,7 @@ end
14
15
 
15
16
  RSpec.configure do |config|
16
17
  config.before(:suite) do
17
- message = "[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting"
18
+ message = '[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See https://github.com/philostler/rspec-sidekiq/wiki/FAQ-&-Troubleshooting'
18
19
  message = "\e[33m#{message}\e[0m" if RSpec::Sidekiq.configuration.enable_terminal_colours
19
20
  puts message if RSpec::Sidekiq.configuration.warn_when_jobs_not_processed_by_sidekiq
20
21
  end
@@ -22,4 +23,4 @@ RSpec.configure do |config|
22
23
  config.before(:each) do
23
24
  Sidekiq::Worker.clear_all if RSpec::Sidekiq.configuration.clear_all_enqueued_jobs
24
25
  end
25
- end
26
+ end
@@ -1,5 +1,6 @@
1
+ # encoding: utf-8
1
2
  module RSpec
2
3
  module Sidekiq
3
- VERSION = "1.1.0"
4
+ VERSION = '2.0.0.beta'
4
5
  end
5
6
  end
@@ -1,33 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/rspec/sidekiq/version", __FILE__)
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/rspec/sidekiq/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "rspec-sidekiq"
5
+ s.name = 'rspec-sidekiq'
6
6
  s.version = RSpec::Sidekiq::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.author = "Phil Ostler"
9
- s.email = "github@philostler.com"
10
- s.homepage = "http://github.com/philostler/rspec-sidekiq"
11
- s.summary = "RSpec for Sidekiq"
12
- s.description = "Simple testing of Sidekiq jobs via a collection of matchers and helpers"
13
- s.license = "MIT"
8
+ s.author = 'Phil Ostler'
9
+ s.email = 'github@philostler.com'
10
+ s.homepage = 'http://github.com/philostler/rspec-sidekiq'
11
+ s.summary = 'RSpec for Sidekiq'
12
+ s.description = 'Simple testing of Sidekiq jobs via a collection of matchers and helpers'
13
+ s.license = 'MIT'
14
14
 
15
- s.add_dependency "rspec", "~> 2.0"
16
- s.add_dependency "sidekiq", ">= 2.4.0"
15
+ s.add_dependency 'rspec', '>= 3.0.0'
16
+ s.add_dependency 'sidekiq', '>= 2.4.0'
17
17
 
18
- s.add_development_dependency "coveralls", "~> 0.7.0"
19
- s.add_development_dependency "fuubar", ">= 1.1.0"
18
+ s.add_development_dependency 'coveralls', '~> 0.7.1'
19
+ s.add_development_dependency 'fuubar', '>= 2.0.0'
20
20
 
21
- s.files = Dir[".gitattributes"] +
22
- Dir[".gitignore"] +
23
- Dir[".rspec"] +
24
- Dir[".simplecov"] +
25
- Dir[".travis"] +
26
- Dir["CHANGES.md"] +
27
- Dir["Gemfile"] +
28
- Dir["LICENSE"] +
29
- Dir["README.md"] +
30
- Dir["rspec-sidekiq.gemspec"] +
31
- Dir["**/*.rb"]
32
- s.require_paths = ["lib"]
21
+ s.files = Dir['.gitattributes'] +
22
+ Dir['.gitignore'] +
23
+ Dir['.rspec'] +
24
+ Dir['.simplecov'] +
25
+ Dir['.travis'] +
26
+ Dir['CHANGES.md'] +
27
+ Dir['Gemfile'] +
28
+ Dir['LICENSE'] +
29
+ Dir['README.md'] +
30
+ Dir['rspec-sidekiq.gemspec'] +
31
+ Dir['**/*.rb']
32
+ s.require_paths = ['lib']
33
33
  end
@@ -1,6 +1,7 @@
1
- require "spec_helper"
1
+ # encoding: utf-8
2
+ require 'spec_helper'
2
3
 
3
- describe "Batch" do
4
+ describe 'Batch' do
4
5
  module Sidekiq
5
6
  module Batch
6
7
  class Status
@@ -8,16 +9,16 @@ describe "Batch" do
8
9
  end
9
10
  end
10
11
 
11
- load File.expand_path(File.join(File.dirname(__FILE__), "../../../lib/rspec/sidekiq/batch.rb"))
12
+ load File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/rspec/sidekiq/batch.rb'))
12
13
 
13
- describe "NullStatus" do
14
- describe "#total" do
15
- it "returns 0 when no jobs" do
14
+ describe 'NullStatus' do
15
+ describe '#total' do
16
+ it 'returns 0 when no jobs' do
16
17
  null_status = Sidekiq::Batch.new.status
17
18
  expect(null_status.total).to eq(0)
18
19
  end
19
20
 
20
- it "returns 1 when 1 job" do
21
+ it 'returns 1 when 1 job' do
21
22
  batch = Sidekiq::Batch.new
22
23
 
23
24
  batch.jobs do
@@ -30,8 +31,8 @@ describe "Batch" do
30
31
  end
31
32
  end
32
33
 
33
- describe "#bid" do
34
- it "returns a bid" do
34
+ describe '#bid' do
35
+ it 'returns a bid' do
35
36
  null_status = Sidekiq::Batch.new
36
37
  expect(null_status.bid).to_not be_nil
37
38
  end
@@ -1,7 +1,7 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'Retries Exhausted block' do
4
-
5
5
  class FooClass < TestWorkerAlternative
6
6
  sidekiq_retries_exhausted do |msg|
7
7
  bar('hello')
@@ -20,7 +20,7 @@ describe 'Retries Exhausted block' do
20
20
  end
21
21
 
22
22
  it 'passes arguments to the block' do
23
- args = {'args' => ['a', 'b']}
23
+ args = { 'args' => ['a', 'b']}
24
24
  FooClass.within_sidekiq_retries_exhausted_block(args) do
25
25
  expect(FooClass).to receive(:foo).with(FooClass.default_retries_exhausted_args.merge(args))
26
26
  end