rspec-que 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rspec/que/queue_up.rb +26 -108
- data/lib/rspec/que/queue_up/queue_count.rb +75 -0
- data/lib/rspec/que/queue_up/queued_args.rb +33 -0
- data/lib/rspec/que/queue_up/queued_at.rb +29 -0
- data/lib/rspec/que/queue_up/queued_class.rb +31 -0
- data/lib/rspec/que/queue_up/queued_priority.rb +29 -0
- data/lib/rspec/que/queue_up/queued_something.rb +22 -0
- data/lib/rspec/que/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ae7da24696fff896e0e4a085e3722eace94a83b
|
4
|
+
data.tar.gz: b86fcdab6635157b959931ab95d53d46bdeba98f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97cad4ef4a5229b2f8308fe48deef30b64bb7d51798f9e27827214111ed575749ea409d2813148bf27c15360cdca11e8e20275d8dbf8382a4034888699663c7
|
7
|
+
data.tar.gz: a5476696af273b6852ecd8dbfbd5142d91ac9d61e2f23c6052ba34546e6f41ea608762f446c00e682d2fd91b24f5e8da9f06f90dd4b733924ca4784d606fa464
|
data/lib/rspec/que/queue_up.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
require 'rspec/mocks/argument_list_matcher'
|
2
2
|
require 'time'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
require_relative 'queue_up/queued_something'
|
6
|
+
require_relative 'queue_up/queued_priority'
|
7
|
+
require_relative 'queue_up/queued_class'
|
8
|
+
require_relative 'queue_up/queued_args'
|
9
|
+
require_relative 'queue_up/queued_at'
|
10
|
+
require_relative 'queue_up/queue_count'
|
3
11
|
|
4
12
|
module RSpec
|
5
13
|
module Que
|
6
14
|
module Matchers
|
7
15
|
class QueueUp
|
8
16
|
include RSpec::Matchers::Composable
|
17
|
+
extend Forwardable
|
9
18
|
|
10
19
|
def initialize(job_class = nil)
|
11
20
|
@matchers = [QueuedSomething.new]
|
12
21
|
@matchers << QueuedClass.new(job_class) if job_class
|
22
|
+
@count_matcher = QueueCount.new(self, QueueCount::EXACTLY, 1)
|
13
23
|
@job_class = job_class
|
14
24
|
@stages = []
|
15
25
|
end
|
@@ -23,7 +33,10 @@ module RSpec
|
|
23
33
|
@stages << { matcher: matcher, candidates: @matched_jobs.dup }
|
24
34
|
@matched_jobs.delete_if { |job| !matcher.matches?(job) }
|
25
35
|
end
|
26
|
-
|
36
|
+
|
37
|
+
@stages << { matcher: @count_matcher, candidates: @matched_jobs.dup }
|
38
|
+
|
39
|
+
@count_matcher.matches?(@matched_jobs.count)
|
27
40
|
end
|
28
41
|
|
29
42
|
def with(*args)
|
@@ -41,6 +54,13 @@ module RSpec
|
|
41
54
|
self
|
42
55
|
end
|
43
56
|
|
57
|
+
def_delegators :@count_matcher,
|
58
|
+
:exactly,
|
59
|
+
:at_least,
|
60
|
+
:at_most,
|
61
|
+
:once,
|
62
|
+
:twice
|
63
|
+
|
44
64
|
def failure_message
|
45
65
|
# last stage to have any candidate jobs
|
46
66
|
failed_stage = @stages.reject do |s|
|
@@ -76,118 +96,16 @@ module RSpec
|
|
76
96
|
end
|
77
97
|
|
78
98
|
def job_description
|
79
|
-
@
|
99
|
+
if @count_matcher.default?
|
100
|
+
@matchers.map(&:desc).join(" ")
|
101
|
+
else
|
102
|
+
[*@matchers, @count_matcher].map(&:desc).join(" ")
|
103
|
+
end
|
80
104
|
end
|
81
105
|
|
82
106
|
def format_job(job)
|
83
107
|
"#{job[:job_class]}[" + job[:args].join(", ") + "]"
|
84
108
|
end
|
85
|
-
|
86
|
-
class QueuedSomething
|
87
|
-
def matches?(_job)
|
88
|
-
true
|
89
|
-
end
|
90
|
-
|
91
|
-
def desc
|
92
|
-
"a job"
|
93
|
-
end
|
94
|
-
|
95
|
-
def failed_msg(_last_found)
|
96
|
-
"nothing"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class QueuedClass
|
101
|
-
attr_reader :job_class
|
102
|
-
def initialize(job_class)
|
103
|
-
@job_class = job_class
|
104
|
-
end
|
105
|
-
|
106
|
-
def matches?(job)
|
107
|
-
job[:job_class] == job_class.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
def desc
|
111
|
-
"of class #{job_class}"
|
112
|
-
end
|
113
|
-
|
114
|
-
def failed_msg(candidates)
|
115
|
-
classes = candidates.map { |c| c[:job_class] }
|
116
|
-
if classes.length == 1
|
117
|
-
classes.first
|
118
|
-
else
|
119
|
-
"#{classes.length} jobs of class [#{classes.join(', ')}]"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
class QueuedArgs
|
125
|
-
def initialize(args)
|
126
|
-
@args = args
|
127
|
-
@argument_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*args)
|
128
|
-
end
|
129
|
-
|
130
|
-
def matches?(job)
|
131
|
-
@argument_list_matcher.args_match?(*job[:args])
|
132
|
-
end
|
133
|
-
|
134
|
-
def desc
|
135
|
-
"with args #{@args}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def failed_msg(candidates)
|
139
|
-
if candidates.length == 1
|
140
|
-
"job enqueued with #{candidates.first[:args]}"
|
141
|
-
else
|
142
|
-
"#{candidates.length} jobs with args: " +
|
143
|
-
candidates.map { |j| j[:args] }.to_s
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
class QueuedAt
|
149
|
-
def initialize(the_time)
|
150
|
-
@time = the_time
|
151
|
-
end
|
152
|
-
|
153
|
-
def matches?(job)
|
154
|
-
job[:run_at] == @time
|
155
|
-
end
|
156
|
-
|
157
|
-
def desc
|
158
|
-
"at #{@time}"
|
159
|
-
end
|
160
|
-
|
161
|
-
def failed_msg(candidates)
|
162
|
-
if candidates.length == 1
|
163
|
-
"job at #{candidates.first[:run_at]}"
|
164
|
-
else
|
165
|
-
"jobs at #{candidates.map { |c| c[:run_at] }}"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
class QueuedPriority
|
171
|
-
def initialize(priority)
|
172
|
-
@priority = priority
|
173
|
-
end
|
174
|
-
|
175
|
-
def matches?(job)
|
176
|
-
job[:priority] == @priority
|
177
|
-
end
|
178
|
-
|
179
|
-
def desc
|
180
|
-
"of priority #{@priority}"
|
181
|
-
end
|
182
|
-
|
183
|
-
def failed_msg(candidates)
|
184
|
-
if candidates.length == 1
|
185
|
-
"job of priority #{candidates.first[:priority]}"
|
186
|
-
else
|
187
|
-
"jobs of priority #{candidates.map { |c| c[:priority] }}"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
109
|
end
|
192
110
|
end
|
193
111
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Que
|
5
|
+
module Matchers
|
6
|
+
class QueueUp
|
7
|
+
class QueueCount
|
8
|
+
EXACTLY = :==
|
9
|
+
AT_LEAST = :>=
|
10
|
+
AT_MOST = :<=
|
11
|
+
|
12
|
+
def initialize(parent_matcher, comparator, number)
|
13
|
+
@number = number
|
14
|
+
@comparator = comparator
|
15
|
+
@parent = parent_matcher
|
16
|
+
end
|
17
|
+
|
18
|
+
def once
|
19
|
+
exactly(1)
|
20
|
+
@parent
|
21
|
+
end
|
22
|
+
|
23
|
+
def twice
|
24
|
+
exactly(2)
|
25
|
+
@parent
|
26
|
+
end
|
27
|
+
|
28
|
+
def exactly(n)
|
29
|
+
set(EXACTLY, n)
|
30
|
+
end
|
31
|
+
|
32
|
+
def at_least(n)
|
33
|
+
set(AT_LEAST, n)
|
34
|
+
end
|
35
|
+
|
36
|
+
def at_most(n)
|
37
|
+
set(AT_MOST, n)
|
38
|
+
end
|
39
|
+
|
40
|
+
def times
|
41
|
+
@parent
|
42
|
+
end
|
43
|
+
|
44
|
+
def matches?(actual_number)
|
45
|
+
actual_number.send(@comparator, @number)
|
46
|
+
end
|
47
|
+
|
48
|
+
def desc
|
49
|
+
case @comparator
|
50
|
+
when EXACTLY then "exactly #{@number} times"
|
51
|
+
when AT_LEAST then "at least #{@number} times"
|
52
|
+
when AT_MOST then "at most #{@number} times"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def failed_msg(candidates)
|
57
|
+
"#{candidates.length} jobs"
|
58
|
+
end
|
59
|
+
|
60
|
+
def default?
|
61
|
+
@comparator == EXACTLY && @number == 1
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def set(comparator, number)
|
67
|
+
@comparator = comparator
|
68
|
+
@number = number
|
69
|
+
self
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Que
|
5
|
+
module Matchers
|
6
|
+
class QueueUp
|
7
|
+
class QueuedArgs
|
8
|
+
def initialize(args)
|
9
|
+
@args = args
|
10
|
+
@argument_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(job)
|
14
|
+
@argument_list_matcher.args_match?(*job[:args])
|
15
|
+
end
|
16
|
+
|
17
|
+
def desc
|
18
|
+
"with args #{@args}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failed_msg(candidates)
|
22
|
+
if candidates.length == 1
|
23
|
+
"job enqueued with #{candidates.first[:args]}"
|
24
|
+
else
|
25
|
+
"#{candidates.length} jobs with args: " +
|
26
|
+
candidates.map { |j| j[:args] }.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Que
|
3
|
+
module Matchers
|
4
|
+
class QueueUp
|
5
|
+
class QueuedAt
|
6
|
+
def initialize(the_time)
|
7
|
+
@time = the_time
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(job)
|
11
|
+
job[:run_at] == @time
|
12
|
+
end
|
13
|
+
|
14
|
+
def desc
|
15
|
+
"at #{@time}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def failed_msg(candidates)
|
19
|
+
if candidates.length == 1
|
20
|
+
"job at #{candidates.first[:run_at]}"
|
21
|
+
else
|
22
|
+
"jobs at #{candidates.map { |c| c[:run_at] }}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Que
|
3
|
+
module Matchers
|
4
|
+
class QueueUp
|
5
|
+
class QueuedClass
|
6
|
+
attr_reader :job_class
|
7
|
+
def initialize(job_class)
|
8
|
+
@job_class = job_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(job)
|
12
|
+
job[:job_class] == job_class.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def desc
|
16
|
+
"of class #{job_class}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failed_msg(candidates)
|
20
|
+
classes = candidates.map { |c| c[:job_class] }
|
21
|
+
if classes.length == 1
|
22
|
+
classes.first
|
23
|
+
else
|
24
|
+
"#{classes.length} jobs of class [#{classes.join(', ')}]"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Que
|
3
|
+
module Matchers
|
4
|
+
class QueueUp
|
5
|
+
class QueuedPriority
|
6
|
+
def initialize(priority)
|
7
|
+
@priority = priority
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(job)
|
11
|
+
job[:priority] == @priority
|
12
|
+
end
|
13
|
+
|
14
|
+
def desc
|
15
|
+
"of priority #{@priority}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def failed_msg(candidates)
|
19
|
+
if candidates.length == 1
|
20
|
+
"job of priority #{candidates.first[:priority]}"
|
21
|
+
else
|
22
|
+
"jobs of priority #{candidates.map { |c| c[:priority] }}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Que
|
3
|
+
module Matchers
|
4
|
+
class QueueUp
|
5
|
+
class QueuedSomething
|
6
|
+
def matches?(_job)
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def desc
|
11
|
+
"a job"
|
12
|
+
end
|
13
|
+
|
14
|
+
def failed_msg(_last_found)
|
15
|
+
"nothing"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/lib/rspec/que/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-que
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-mocks
|
@@ -79,6 +79,12 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- lib/rspec/que.rb
|
81
81
|
- lib/rspec/que/queue_up.rb
|
82
|
+
- lib/rspec/que/queue_up/queue_count.rb
|
83
|
+
- lib/rspec/que/queue_up/queued_args.rb
|
84
|
+
- lib/rspec/que/queue_up/queued_at.rb
|
85
|
+
- lib/rspec/que/queue_up/queued_class.rb
|
86
|
+
- lib/rspec/que/queue_up/queued_priority.rb
|
87
|
+
- lib/rspec/que/queue_up/queued_something.rb
|
82
88
|
- lib/rspec/que/version.rb
|
83
89
|
- rspec-que.gemspec
|
84
90
|
homepage: http://github.com/gocardless/rspec-que
|
@@ -101,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
107
|
version: '0'
|
102
108
|
requirements: []
|
103
109
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.1
|
105
111
|
signing_key:
|
106
112
|
specification_version: 4
|
107
113
|
summary: RSpec matchers to test Que
|