resque_spec 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -120,6 +120,43 @@ You can check the size of the queue in your specs too.
120
120
  end
121
121
  end
122
122
 
123
+ Performing Jobs in Specs
124
+ ------------------------
125
+
126
+ Normally, Resque does not perform queued jobs within tests. You may want to
127
+ make assertions based on the result of your jobs. To process jobs immediately,
128
+ you can pass a block to the `with_resque` helper:
129
+
130
+ Given this scenario
131
+
132
+ Given a game
133
+ When I score
134
+ Then the game has a score
135
+
136
+ I might write this as a Cucumber step
137
+
138
+ When /I score/ do
139
+ with_resque do
140
+ visit game_path
141
+ click_link 'Score!'
142
+ end
143
+ end
144
+
145
+ Or I write this spec using the `with_resque` helper
146
+
147
+ describe "#score!" do
148
+ before do
149
+ ResqueSpec.reset!
150
+ end
151
+
152
+ it "increases the score" do
153
+ with_resque do
154
+ game.score!
155
+ end
156
+ game.score.should == 10
157
+ end
158
+ end
159
+
123
160
  Note on Patches/Pull Requests
124
161
  =============================
125
162
 
@@ -0,0 +1,28 @@
1
+ module ResqueSpec
2
+ module Helpers
3
+
4
+ def with_resque
5
+ enable_perform
6
+ yield
7
+ disable_perform
8
+ end
9
+
10
+ private
11
+
12
+ def enable_perform
13
+ ::Resque.module_eval do
14
+ def self.enqueue(klass, *args)
15
+ klass.perform(*args)
16
+ end
17
+ end
18
+ end
19
+
20
+ def disable_perform
21
+ ::Resque.module_eval do
22
+ def self.enqueue(klass, *args)
23
+ ResqueSpec::Resque.enqueue(klass, *args)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -31,6 +31,7 @@ module ResqueSpec
31
31
  end
32
32
 
33
33
  module Resque
34
+ extend self
34
35
  def enqueue(klass, *args)
35
36
  ResqueSpec.queue_for(klass) << {:klass => klass, :args => args}
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module ResqueSpec
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/resque_spec.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'resque_spec/resque_spec'
2
2
  require 'resque_spec/resque_scheduler_spec'
3
+ require 'resque_spec/helpers'
3
4
 
4
- module ResqueSpec
5
- VERSION = '0.4.0'.freeze
6
- end
5
+ config = RSpec.configuration
6
+ config.include ResqueSpec::Helpers
7
+
8
+ World(ResqueSpec::Helpers) if defined?(Cucumber)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Les Hill
@@ -58,6 +58,7 @@ extensions: []
58
58
  extra_rdoc_files: []
59
59
 
60
60
  files:
61
+ - lib/resque_spec/helpers.rb
61
62
  - lib/resque_spec/resque_scheduler_spec.rb
62
63
  - lib/resque_spec/resque_spec.rb
63
64
  - lib/resque_spec/version.rb