resque_spec 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,8 +25,10 @@ What is ResqueSpec?
25
25
  ===================
26
26
 
27
27
  ResqueSpec implements the *stable API* for Resque 1.19.x (which is `enqueue`,
28
- `enqueue_to` (*unreleased*), `dequeue`, `reserve`, and the Resque hooks). It
29
- does not have a test double for Redis, so this may lead to some interesting and
28
+ `enqueue_to` (*unreleased*), `dequeue`, `reserve`, the Resque hooks, and
29
+ because of the way `resque_scheduler` works `Job.create` and `Job.destroy`).
30
+
31
+ It does not have a test double for Redis, so this may lead to some interesting and
30
32
  puzzling behaviour if you use some of the popular Resque plugins (such as
31
33
  `resque_lock`).
32
34
 
@@ -131,9 +133,51 @@ And I write this spec using the `resque_spec` matcher
131
133
  end
132
134
  end
133
135
 
134
- (And I take note of the `before` block that is calling `reset!` for every spec)
136
+ And I might use the `at` statement to specify the time:
137
+
138
+ describe "#recalculate" do
139
+ before do
140
+ ResqueSpec.reset!
141
+ end
142
+
143
+ it "adds person.calculate to the Person queue" do
144
+ person.recalculate
145
+
146
+ # Is it scheduled to be executed at 2010-02-14 06:00:00 ?
147
+ Person.should have_scheduled(person.id, :calculate).at(Time.mktime(2010,2,14,6,0,0))
148
+ end
149
+ end
135
150
 
136
- *(There is also a **have_scheduled_at** matcher)*
151
+ And I might use the `in` statement to specify time interval (in seconds):
152
+
153
+ describe "#recalculate" do
154
+ before do
155
+ ResqueSpec.reset!
156
+ end
157
+
158
+ it "adds person.calculate to the Person queue" do
159
+ person.recalculate
160
+
161
+ # Is it scheduled to be executed in 5 minutes?
162
+ Person.should have_scheduled(person.id, :calculate).in(5 * 60)
163
+ end
164
+ end
165
+
166
+ You can also check the size of the schedule:
167
+
168
+ describe "#recalculate" do
169
+ before do
170
+ ResqueSpec.reset!
171
+ end
172
+
173
+ it "adds person.calculate to the Person queue" do
174
+ person.recalculate
175
+
176
+ Person.should have_schedule_size_of(1)
177
+ end
178
+ end
179
+
180
+ (And I take note of the `before` block that is calling `reset!` for every spec)
137
181
 
138
182
  And I might write this as a Cucumber step
139
183
 
@@ -33,6 +33,7 @@ module Resque
33
33
  return if run_before_enqueue(klass, *args)
34
34
  Job.create(queue, klass, *args)
35
35
  run_after_enqueue(klass, *args)
36
+ true
36
37
  end
37
38
  end
38
39
 
@@ -64,16 +64,41 @@ RSpec::Matchers.define :have_queue_size_of do |size|
64
64
  end
65
65
 
66
66
  RSpec::Matchers.define :have_scheduled do |*expected_args|
67
+ chain :at do |timestamp|
68
+ @interval = nil
69
+ @time = timestamp
70
+ @time_info = "at #{@time}"
71
+ end
72
+
73
+ chain :in do |interval|
74
+ @time = nil
75
+ @interval = interval
76
+ @time_info = "in #{@interval} seconds"
77
+ end
78
+
67
79
  match do |actual|
68
- ResqueSpec.schedule_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:args] == expected_args }
80
+ ResqueSpec.schedule_for(actual).any? do |entry|
81
+ class_matches = entry[:class].to_s == actual.to_s
82
+ args_match = entry[:args] == expected_args
83
+
84
+ time_matches = if @time
85
+ entry[:time] == @time
86
+ elsif @interval
87
+ entry[:time].to_i == entry[:stored_at].to_i + @interval
88
+ else
89
+ true
90
+ end
91
+
92
+ class_matches && args_match && time_matches
93
+ end
69
94
  end
70
95
 
71
96
  failure_message_for_should do |actual|
72
- "expected that #{actual} would have [#{expected_args.join(', ')}] scheduled"
97
+ ["expected that #{actual} would have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
73
98
  end
74
99
 
75
100
  failure_message_for_should_not do |actual|
76
- "expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled"
101
+ ["expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
77
102
  end
78
103
 
79
104
  description do
@@ -82,6 +107,8 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
82
107
  end
83
108
 
84
109
  RSpec::Matchers.define :have_scheduled_at do |*expected_args|
110
+ warn "DEPRECATION WARNING: have_scheduled_at(time, *args) is deprecated and will be removed in future. Please use have_scheduled(*args).at(time) instead."
111
+
85
112
  match do |actual|
86
113
  time = expected_args.first
87
114
  other_args = expected_args[1..-1]
@@ -16,7 +16,7 @@ module ResqueSpec
16
16
  end
17
17
 
18
18
  def enqueue_at(time, klass, *args)
19
- perform_or_store(schedule_queue_name(klass), :class => klass.to_s, :time => time, :args => args)
19
+ perform_or_store(schedule_queue_name(klass), :class => klass.to_s, :time => time, :stored_at => Time.now, :args => args)
20
20
  end
21
21
 
22
22
  def enqueue_in(time, klass, *args)
@@ -1,3 +1,3 @@
1
1
  module ResqueSpec
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/resque_spec.rb CHANGED
@@ -93,7 +93,8 @@ module ResqueSpec
93
93
  def payload_with_string_keys(payload)
94
94
  {
95
95
  'class' => payload[:class],
96
- 'args' => payload[:args]
96
+ 'args' => payload[:args],
97
+ 'stored_at' => payload[:stored_at]
97
98
  }
98
99
  end
99
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-08 00:00:00.000000000Z
12
+ date: 2012-01-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
16
- requirement: &70309046836280 !ruby/object:Gem::Requirement
16
+ requirement: &70229397540720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.19.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70309046836280
24
+ version_requirements: *70229397540720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70309046834900 !ruby/object:Gem::Requirement
27
+ requirement: &70229397540220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70309046834900
35
+ version_requirements: *70229397540220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-debug19
38
- requirement: &70309046834260 !ruby/object:Gem::Requirement
38
+ requirement: &70229397539840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70309046834260
46
+ version_requirements: *70229397539840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: timecop
49
- requirement: &70309046826600 !ruby/object:Gem::Requirement
49
+ requirement: &70229397539380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70309046826600
57
+ version_requirements: *70229397539380
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70229397538960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70229397538960
58
69
  description: RSpec matchers for Resque
59
70
  email: leshill@gmail.com
60
71
  executables: []