queue_classic_matchers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/lib/queue_classic_matchers/test_helper.rb +11 -0
- data/lib/queue_classic_matchers/test_worker.rb +28 -0
- data/lib/queue_classic_matchers/version.rb +3 -0
- data/lib/queue_classic_matchers.rb +129 -0
- data/queue_classic_matchers.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cfabef2f107163c77342e176369028419df0b9e
|
4
|
+
data.tar.gz: 7c3e40864f608225424faa87aa95c55d5dc0df50
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68fcb9b92713b041b25859fc6ed13024023e5a55b9a0504d2098359faa0e66af21147c28e29aa005018dc8cbdc3951ce2dca4a01fc3068669e5f5e6ba7574173
|
7
|
+
data.tar.gz: 7d3997f9b70c53a8d1c98ed5a1624b41960d1701ac74972e91d802a84b083ad4209ddfefee0757d636943601cc0ab7aa936e3358f62fdd7e1643075cc16f5408
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
tags
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.1.2@queue_classic_matchers --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Simon Mathieu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# QueueClassicMatchers
|
2
|
+
|
3
|
+
Test helpers and RSpec matchers to [QueueClassicPlus](https://github.com/rainforestapp/queue_classic_plus).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'queue_classic_matchers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install queue_classic_matchers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
### Matchers
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
expect(MyQueueClassicPlusJob).to have_queued(*my_args)
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
### Test Helper
|
31
|
+
|
32
|
+
Run a subset of the jobs in a queue. Delete the others.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
run_queue q_name, [MyQueueClassicPlusJob]
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/queue_classic_matchers/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module QueueClassicMatchers
|
2
|
+
class TestWorker < QC::Worker
|
3
|
+
def initialize(options)
|
4
|
+
@klasses = options.delete(:klasses)
|
5
|
+
super(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def handle_failure(job, e)
|
9
|
+
raise e
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(queue, job)
|
13
|
+
# Skip over task not matching klasses
|
14
|
+
k = job[:method].split('.').first
|
15
|
+
if @klasses.nil? || klasses.include?(k)
|
16
|
+
super
|
17
|
+
else
|
18
|
+
# Uncomment for debugging
|
19
|
+
# puts "Skipping #{job[:method]}. Klassed: #{klasses.inspect}"
|
20
|
+
queue.delete(job[:id])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def klasses
|
25
|
+
@klasses.map(&:to_s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require "queue_classic_matchers/version"
|
3
|
+
require "queue_classic_matchers/test_worker"
|
4
|
+
require "queue_classic_matchers/test_helper"
|
5
|
+
|
6
|
+
module QueueClassicMatchers
|
7
|
+
# Your code goes here...
|
8
|
+
module QueueClassicMatchers::QueueClassicRspec
|
9
|
+
def self.find_by_args(queue_name, method, args, table = "queue_classic_jobs")
|
10
|
+
q = "SELECT * FROM #{table} WHERE q_name = $1 AND method = $2 AND args::text = $3"
|
11
|
+
result = QC.default_conn_adapter.execute q, queue_name, method, JSON.dump(args)
|
12
|
+
result = [result] unless Array === result
|
13
|
+
result.compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.reset!
|
17
|
+
QC.default_conn_adapter.execute "DELETE FROM queue_classic_jobs"
|
18
|
+
QC.default_conn_adapter.execute "DELETE FROM queue_classic_later_jobs"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
RSpec::Matchers.define :have_queued do |*expected|
|
24
|
+
match do |actual|
|
25
|
+
method = "#{actual.to_s}._perform"
|
26
|
+
queue_name = actual.queue.name
|
27
|
+
results = QueueClassicMatchers::QueueClassicRspec.find_by_args(queue_name, method, expected)
|
28
|
+
results.size > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
failure_message do |actual|
|
32
|
+
"should have queued #{actual.inspect} with #{expected.inspect}"
|
33
|
+
end
|
34
|
+
|
35
|
+
failure_message_when_negated do |actual|
|
36
|
+
"should not have queued #{actual.inspect}"
|
37
|
+
end
|
38
|
+
|
39
|
+
description do
|
40
|
+
"should enqueue in queue classic"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec::Matchers.define :have_queue_size_of do |expected|
|
45
|
+
match do |actual|
|
46
|
+
actual.queue.count == expected
|
47
|
+
end
|
48
|
+
|
49
|
+
failure_message do |actual|
|
50
|
+
"should have a queue size of #{expected}. (#{actual.queue.count} instead)"
|
51
|
+
end
|
52
|
+
|
53
|
+
failure_message_when_negated do |actual|
|
54
|
+
"should not have a queue size of #{expected}."
|
55
|
+
end
|
56
|
+
|
57
|
+
description do
|
58
|
+
"should have a queue size of #{expected}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
RSpec::Matchers.define :change_queue_size_of do |expected|
|
63
|
+
supports_block_expectations
|
64
|
+
|
65
|
+
chain :by do |amount|
|
66
|
+
@amount = amount
|
67
|
+
end
|
68
|
+
|
69
|
+
def amount
|
70
|
+
@amount || 1
|
71
|
+
end
|
72
|
+
|
73
|
+
match do |actual|
|
74
|
+
old = expected.queue.count
|
75
|
+
actual.call
|
76
|
+
new = expected.queue.count
|
77
|
+
|
78
|
+
new - old == (amount || 1)
|
79
|
+
end
|
80
|
+
|
81
|
+
failure_message do |actual|
|
82
|
+
"should have a queue size of #{expected} by #{amount}"
|
83
|
+
end
|
84
|
+
|
85
|
+
failure_message_when_negated do |actual|
|
86
|
+
"should not have a queue size of #{expected} by #{amount}"
|
87
|
+
end
|
88
|
+
|
89
|
+
description do
|
90
|
+
"should change the queue size"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
RSpec::Matchers.define :have_scheduled do |*expected_args|
|
96
|
+
chain :at do |timestamp|
|
97
|
+
@interval = nil
|
98
|
+
@time = timestamp
|
99
|
+
@time_info = "at #{@time}"
|
100
|
+
end
|
101
|
+
|
102
|
+
match do |actual|
|
103
|
+
method = "#{actual.to_s}._perform"
|
104
|
+
queue_name = actual.queue.name
|
105
|
+
results = QueueClassicMatchers::QueueClassicRspec.find_by_args(queue_name,
|
106
|
+
method,
|
107
|
+
expected_args,
|
108
|
+
"queue_classic_later_jobs")
|
109
|
+
results.any? do |entry|
|
110
|
+
time_matches = if @time
|
111
|
+
Time.parse(entry['not_before']).to_i == @time.to_i
|
112
|
+
else
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
failure_message do |actual|
|
119
|
+
["expected that #{actual} would have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
|
120
|
+
end
|
121
|
+
|
122
|
+
failure_message_when_negated do |actual|
|
123
|
+
["expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
|
124
|
+
end
|
125
|
+
|
126
|
+
description do
|
127
|
+
"have scheduled arguments"
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'queue_classic_matchers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "queue_classic_matchers"
|
8
|
+
spec.version = QueueClassicMatchers::VERSION
|
9
|
+
spec.authors = ["Simon Mathieu"]
|
10
|
+
spec.email = ["simon.math@gmail.com"]
|
11
|
+
spec.summary = %q{RSpec Matchers and helpers for QueueClassicPlus}
|
12
|
+
spec.description = %q{RSpec Matchers and helpers for QueueClassicPlus}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: queue_classic_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Mathieu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: RSpec Matchers and helpers for QueueClassicPlus
|
42
|
+
email:
|
43
|
+
- simon.math@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rvmrc"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/queue_classic_matchers.rb
|
55
|
+
- lib/queue_classic_matchers/test_helper.rb
|
56
|
+
- lib/queue_classic_matchers/test_worker.rb
|
57
|
+
- lib/queue_classic_matchers/version.rb
|
58
|
+
- queue_classic_matchers.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: RSpec Matchers and helpers for QueueClassicPlus
|
83
|
+
test_files: []
|