rspec-sidekiq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitattributes ADDED
@@ -0,0 +1,22 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+ *.sln merge=union
7
+ *.csproj merge=union
8
+ *.vbproj merge=union
9
+ *.fsproj merge=union
10
+ *.dbproj merge=union
11
+
12
+ # Standard to msysgit
13
+ *.doc diff=astextplain
14
+ *.DOC diff=astextplain
15
+ *.docx diff=astextplain
16
+ *.DOCX diff=astextplain
17
+ *.dot diff=astextplain
18
+ *.DOT diff=astextplain
19
+ *.pdf diff=astextplain
20
+ *.PDF diff=astextplain
21
+ *.rtf diff=astextplain
22
+ *.RTF diff=astextplain
data/.gitignore ADDED
@@ -0,0 +1,163 @@
1
+ #################
2
+ ## Eclipse
3
+ #################
4
+
5
+ *.pydevproject
6
+ .project
7
+ .metadata
8
+ bin/
9
+ tmp/
10
+ *.tmp
11
+ *.bak
12
+ *.swp
13
+ *~.nib
14
+ local.properties
15
+ .classpath
16
+ .settings/
17
+ .loadpath
18
+
19
+ # External tool builders
20
+ .externalToolBuilders/
21
+
22
+ # Locally stored "Eclipse launch configurations"
23
+ *.launch
24
+
25
+ # CDT-specific
26
+ .cproject
27
+
28
+ # PDT-specific
29
+ .buildpath
30
+
31
+
32
+ #################
33
+ ## Visual Studio
34
+ #################
35
+
36
+ ## Ignore Visual Studio temporary files, build results, and
37
+ ## files generated by popular Visual Studio add-ons.
38
+
39
+ # User-specific files
40
+ *.suo
41
+ *.user
42
+ *.sln.docstates
43
+
44
+ # Build results
45
+ [Dd]ebug/
46
+ [Rr]elease/
47
+ *_i.c
48
+ *_p.c
49
+ *.ilk
50
+ *.meta
51
+ *.obj
52
+ *.pch
53
+ *.pdb
54
+ *.pgc
55
+ *.pgd
56
+ *.rsp
57
+ *.sbr
58
+ *.tlb
59
+ *.tli
60
+ *.tlh
61
+ *.tmp
62
+ *.vspscc
63
+ .builds
64
+ *.dotCover
65
+
66
+ ## TODO: If you have NuGet Package Restore enabled, uncomment this
67
+ #packages/
68
+
69
+ # Visual C++ cache files
70
+ ipch/
71
+ *.aps
72
+ *.ncb
73
+ *.opensdf
74
+ *.sdf
75
+
76
+ # Visual Studio profiler
77
+ *.psess
78
+ *.vsp
79
+
80
+ # ReSharper is a .NET coding add-in
81
+ _ReSharper*
82
+
83
+ # Installshield output folder
84
+ [Ee]xpress
85
+
86
+ # DocProject is a documentation generator add-in
87
+ DocProject/buildhelp/
88
+ DocProject/Help/*.HxT
89
+ DocProject/Help/*.HxC
90
+ DocProject/Help/*.hhc
91
+ DocProject/Help/*.hhk
92
+ DocProject/Help/*.hhp
93
+ DocProject/Help/Html2
94
+ DocProject/Help/html
95
+
96
+ # Click-Once directory
97
+ publish
98
+
99
+ # Others
100
+ [Bb]in
101
+ [Oo]bj
102
+ sql
103
+ TestResults
104
+ *.Cache
105
+ ClientBin
106
+ stylecop.*
107
+ ~$*
108
+ *.dbmdl
109
+ Generated_Code #added for RIA/Silverlight projects
110
+
111
+ # Backup & report files from converting an old project file to a newer
112
+ # Visual Studio version. Backup files are not needed, because we have git ;-)
113
+ _UpgradeReport_Files/
114
+ Backup*/
115
+ UpgradeLog*.XML
116
+
117
+
118
+
119
+ ############
120
+ ## Windows
121
+ ############
122
+
123
+ # Windows image file caches
124
+ Thumbs.db
125
+
126
+ # Folder config file
127
+ Desktop.ini
128
+
129
+
130
+ #############
131
+ ## Python
132
+ #############
133
+
134
+ *.py[co]
135
+
136
+ # Packages
137
+ *.egg
138
+ *.egg-info
139
+ dist
140
+ build
141
+ eggs
142
+ parts
143
+ bin
144
+ var
145
+ sdist
146
+ develop-eggs
147
+ .installed.cfg
148
+
149
+ # Installer logs
150
+ pip-log.txt
151
+
152
+ # Unit test / coverage reports
153
+ .coverage
154
+ .tox
155
+
156
+ #Translations
157
+ *.mo
158
+
159
+ #Mr Developer
160
+ .mr.developer.cfg
161
+
162
+ # Mac crap
163
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format Fuubar
3
+ --format html --out rspec_results.html
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.1.0
2
+ ---
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013 Phil Ostler
4
+
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
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # RSpec for Sidekiq [![Code Climate][code_climate_badge]][code_climate] [![Travis CI][travis_ci_badge]][travis_ci] [![Gemnasium][gemnasium_badge]][gemnasium]
2
+ *Simple testing of Sidekiq jobs via a collection of matchers and common tasks*
3
+
4
+ [RubyGems][ruby_gems] | [Code Climate][code_climate] | [GitHub][github] | [Travis CI][travis_ci] | [Gemnasium][gemnasium] | [RubyDoc][ruby_doc] | [Ruby Toolbox][ruby_toolbox]
5
+
6
+ ## Installation
7
+ ```
8
+ gem "rspec-sidekiq"
9
+ ```
10
+ There is no need to ```require "sidekiq/testing"``` when using rspec-sidekiq
11
+
12
+ ## Configuration
13
+ ```ruby
14
+ RSpec::Sidekiq.configure do |config|
15
+ # Clears all job queues before each example
16
+ config.clear_all_enqueued_jobs = false # default => true
17
+ end
18
+ ```
19
+
20
+ ## Matchers
21
+ * [be_processed_in](#be_processed_in)
22
+ * [be_retryable](#be_retryable)
23
+ * [be_unique](#be_unique)
24
+ * [have_enqueued_jobs](#have_enqueued_jobs)
25
+
26
+ ### be_processed_in
27
+ *Describes the queue that the job should be processed in*
28
+ ```ruby
29
+ it { should be_processed_in :download } } # one liner
30
+ expect(AwesomeJob).to be_processed_in :download # new expect syntax
31
+ ```
32
+
33
+ ### be_retryable
34
+ *Describes if the job retries when there is a failure in it's execution*
35
+ ```ruby
36
+ it { should be_retryable true } } # one liner
37
+ expect(AwesomeJob).to be_retryable true # new expect syntax
38
+ ```
39
+
40
+ ### be_unique (Only available when using [sidekiq-middleware](https://github.com/krasnoukhov/sidekiq-middleware))
41
+ *Describes if the job should be unique within it's queue*
42
+ ```ruby
43
+ it { should be_unique } } # one liner
44
+ expect(AwesomeJob).to be_unique # new expect syntax
45
+ ```
46
+
47
+ ### have_enqueued_jobs
48
+ *Evaluates the number of enqueued jobs for a specified job*
49
+ ```ruby
50
+ expect(AwesomeJob).to have_enqueued_jobs(1) # new expect syntax
51
+ ```
52
+
53
+ ## Testing
54
+ ```bundle exec rspec spec```
55
+
56
+ ## Contribute
57
+ Yes do it! If there's a feature missing that you'd love them get in on the action!
58
+
59
+ Issues/Pull Requests/Comments bring them on...
60
+
61
+ [code_climate]: https://codeclimate.com/github/philostler/rspec-sidekiq
62
+ [code_climate_badge]: https://codeclimate.com/github/philostler/rspec-sidekiq.png
63
+ [gemnasium]: https://gemnasium.com/philostler/rspec-sidekiq
64
+ [gemnasium_badge]: https://gemnasium.com/philostler/rspec-sidekiq.png
65
+ [github]: http://github.com/philostler/rspec-sidekiq
66
+ [ruby_doc]: http://rubydoc.info/github/philostler/rspec-sidekiq/master/frames
67
+ [ruby_gems]: http://rubygems.org/gems/rspec-sidekiq
68
+ [ruby_toolbox]: http://www.ruby-toolbox.com/projects/rspec-sidekiq
69
+ [travis_ci]: http://travis-ci.org/philostler/rspec-sidekiq
70
+ [travis_ci_badge]: https://secure.travis-ci.org/philostler/rspec-sidekiq.png
@@ -0,0 +1,5 @@
1
+ require "sidekiq/testing"
2
+
3
+ require "rspec/sidekiq/configuration"
4
+ require "rspec/sidekiq/matchers"
5
+ require "rspec/sidekiq/sidekiq"
@@ -0,0 +1,11 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ class Configuration
4
+ attr_accessor :clear_all_enqueued_jobs
5
+
6
+ def initialize
7
+ @clear_all_enqueued_jobs = true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "rspec/sidekiq/matchers/be_processed_in"
2
+ require "rspec/sidekiq/matchers/be_retryable"
3
+ require "rspec/sidekiq/matchers/have_enqueued_jobs"
4
+
5
+ if defined?(Sidekiq::Middleware::Client::UniqueJobs)
6
+ require "rspec/sidekiq/matchers/be_unique"
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.include RSpec::Sidekiq::Matchers
11
+ end
@@ -0,0 +1,33 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def be_processed_in expected
5
+ BeProcessedIn.new expected
6
+ end
7
+
8
+ class BeProcessedIn
9
+ def initialize expected
10
+ @expected = expected
11
+ end
12
+
13
+ def description
14
+ "be processed in the \"#{@expected}\" queue"
15
+ end
16
+
17
+ def failure_message
18
+ "expected #{@klass} to be processed in the #{@expected} queue but got #{@actual}"
19
+ end
20
+
21
+ def matches? job
22
+ @klass = job.class
23
+ @actual = @klass.get_sidekiq_options["queue"]
24
+ @actual == @expected
25
+ end
26
+
27
+ def negative_failure_message
28
+ "expected #{@klass} to not be processed in the #{@expected} queue"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def be_retryable expected
5
+ BeRetryable.new expected
6
+ end
7
+
8
+ class BeRetryable
9
+ def initialize expected
10
+ @expected = expected
11
+ end
12
+
13
+ def description
14
+ "retry #{number_of_description} times"
15
+ end
16
+
17
+ def failure_message
18
+ "expected #{@klass} to retry #{number_of_description} times but got #{@actual}"
19
+ end
20
+
21
+ def matches? job
22
+ @klass = job.class
23
+ @actual = @klass.get_sidekiq_options["retry"]
24
+ @actual == @expected
25
+ end
26
+
27
+ def negative_failure_message
28
+ "expected #{@klass} to not retry #{number_of_description} times"
29
+ end
30
+
31
+ def number_of_description
32
+ @expected.is_a?(Fixnum) ? @expected : "the default number of"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def be_unique
5
+ BeUnique.new
6
+ end
7
+
8
+ class BeUnique
9
+ def description
10
+ "be unique in the queue"
11
+ end
12
+
13
+ def failure_message
14
+ "expected #{@klass} to be unique in the queue but it is not"
15
+ end
16
+
17
+ def matches? job
18
+ @klass = job.class
19
+ @actual = @klass.get_sidekiq_options["unique"]
20
+ @actual == true
21
+ end
22
+
23
+ def negative_failure_message
24
+ "expected #{@klass} to not be unique in the queue"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ module Matchers
4
+ def have_enqueued_jobs expected
5
+ HaveEnqueuedJobs.new expected
6
+ end
7
+
8
+ class HaveEnqueuedJobs
9
+ def initialize expected
10
+ @expected = expected
11
+ end
12
+
13
+ def description
14
+ "enqueues a #{@klass} job"
15
+ end
16
+
17
+ def failure_message
18
+ "expected #{@klass} to have #{@expected} enqueued jobs but got #{@actual}"
19
+ end
20
+
21
+ def matches? klass
22
+ @klass = klass
23
+ @actual = klass.jobs.size
24
+ @actual == @expected
25
+ end
26
+
27
+ def negative_failure_message
28
+ "expected #{@klass} to not have #{@expected} enqueued jobs"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ class << self
4
+ def configure &block
5
+ yield configuration
6
+
7
+ configuration
8
+ end
9
+
10
+ def configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.before(:each) do
19
+ Sidekiq::Worker.clear_all if RSpec::Sidekiq.configuration.clear_all_enqueued_jobs
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Sidekiq
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/rspec/sidekiq/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rspec-sidekiq"
6
+ s.version = RSpec::Sidekiq::VERSION
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 common tasks"
13
+ s.license = "MIT"
14
+
15
+ s.add_dependency "rspec", "~> 2.0"
16
+ s.add_dependency "sidekiq", ">= 2.4.0"
17
+
18
+ s.add_development_dependency "fuubar", "~> 1.1"
19
+ s.add_development_dependency "rspec", "~> 2.0"
20
+ s.add_development_dependency "sidekiq", ">= 2.4.0"
21
+
22
+ s.files = Dir[".gitattributes"] +
23
+ Dir[".gitignore"] +
24
+ Dir[".rspec"] +
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
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe "Version" do
4
+ subject { RSpec::Sidekiq::VERSION }
5
+
6
+ expect_it { to eq("0.1.0") }
7
+ end
@@ -0,0 +1,15 @@
1
+ require "sidekiq"
2
+ require "rspec-sidekiq"
3
+
4
+ RSpec.configure do |config|
5
+ config.alias_example_to :expect_it
6
+
7
+ config.expect_with :rspec do |config|
8
+ config.syntax = :expect
9
+ end
10
+ end
11
+
12
+ RSpec::Core::MemoizedHelpers.module_eval do
13
+ alias to should
14
+ alias to_not should_not
15
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Ostler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sidekiq
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.4.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.4.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: fuubar
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sidekiq
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.4.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.4.0
94
+ description: Simple testing of Sidekiq jobs via a collection of matchers and common
95
+ tasks
96
+ email: github@philostler.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitattributes
102
+ - .gitignore
103
+ - .rspec
104
+ - CHANGES.md
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - rspec-sidekiq.gemspec
109
+ - lib/rspec/sidekiq/configuration.rb
110
+ - lib/rspec/sidekiq/matchers/be_processed_in.rb
111
+ - lib/rspec/sidekiq/matchers/be_retryable.rb
112
+ - lib/rspec/sidekiq/matchers/be_unique.rb
113
+ - lib/rspec/sidekiq/matchers/have_enqueued_jobs.rb
114
+ - lib/rspec/sidekiq/matchers.rb
115
+ - lib/rspec/sidekiq/sidekiq.rb
116
+ - lib/rspec/sidekiq/version.rb
117
+ - lib/rspec-sidekiq.rb
118
+ - spec/rspec/sidekiq/version_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: http://github.com/philostler/rspec-sidekiq
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: RSpec for Sidekiq
145
+ test_files: []