resque_spec 0.1.2 → 0.2.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.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ResqueSpec
2
2
  ==========
3
3
 
4
- A simple RSpec and Cucumber matcher for Resque.enqueue, loosely based on
4
+ A simple RSpec and Cucumber matcher for Resque.enqueue and Resque.enqueue_at (from `ResqueScheduler`), loosely based on
5
5
  [http://github.com/justinweiss/resque_unit](resque_unit).
6
6
 
7
7
  This should work with Resque v1.6.0 and up and RSpec v1.3.0 and up.
@@ -61,8 +61,49 @@ Then I write some code to make it pass:
61
61
  end
62
62
  end
63
63
 
64
+ ResqueScheduler with Specs
65
+ --------------------------
64
66
 
65
- == Note on Patches/Pull Requests
67
+ Given this scenario
68
+
69
+ Given a person
70
+ When I schedule a recalculate
71
+ Then the person has calculate scheduled
72
+
73
+ And I write this spec using the `resque_spec` matcher
74
+
75
+ describe "#recalculate" do
76
+ before do
77
+ ResqueSpec.reset!
78
+ end
79
+
80
+ it "adds person.calculate to the Person queue" do
81
+ person.recalculate
82
+ Person.should have_scheduled(person.id, :calculate)
83
+ end
84
+ end
85
+
86
+ (And I take note of the `before` block that is calling `reset!` for every spec)
87
+
88
+ And I might write this as a Cucumber step
89
+
90
+ Then /the (\w?) has (\w?) scheduled/ do |thing, method|
91
+ thing_obj = instance_variable_get("@#{thing}")
92
+ thing_obj.class.should have_scheduled(thing_obj.id, method.to_sym)
93
+ end
94
+
95
+ Then I write some code to make it pass:
96
+
97
+ class Person
98
+ @queue = :people
99
+
100
+ def recalculate
101
+ Resque.enqueue_at(Time.now + 3600, Person, id, :calculate)
102
+ end
103
+ end
104
+
105
+ Note on Patches/Pull Requests
106
+ =============================
66
107
 
67
108
  * Fork the project.
68
109
  * Make your feature addition or bug fix.
@@ -72,6 +113,7 @@ Then I write some code to make it pass:
72
113
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
73
114
  * Send me a pull request. Bonus points for topic branches.
74
115
 
75
- == Copyright
116
+ Copyright
117
+ =========
76
118
 
77
119
  Copyright (c) 2010 Les Hill. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -0,0 +1,62 @@
1
+ require 'resque_spec'
2
+
3
+ module ResqueSpec
4
+
5
+ def scheduled?(klass, time, *args)
6
+ schedule_for(klass).any? {|entry| entry[:klass] == klass && entry[:time] == time && entry[:args] == args}
7
+ end
8
+
9
+ def scheduled_anytime?(klass, *args)
10
+ schedule_for(klass).any? {|entry| entry[:klass] == klass && entry[:args] == args}
11
+ end
12
+
13
+ def schedule_for(klass)
14
+ name = queue_name(klass).to_s << "_scheduled"
15
+ queues[name]
16
+ end
17
+
18
+ module ResqueScheduler
19
+ def enqueue_at(time, klass, *args)
20
+ ResqueSpec.schedule_for(klass) << {:klass => klass, :time => time, :args => args}
21
+ end
22
+ end
23
+ end
24
+
25
+ Resque.extend(ResqueSpec::ResqueScheduler)
26
+
27
+ Spec::Matchers.define :have_scheduled do |*expected_args|
28
+ match do |actual|
29
+ ResqueSpec.scheduled_anytime?(actual, *expected_args)
30
+ end
31
+
32
+ failure_message_for_should do |actual|
33
+ "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
34
+ end
35
+
36
+ failure_message_for_should_not do |actual|
37
+ "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
38
+ end
39
+
40
+ description do
41
+ "have scheduled arguments"
42
+ end
43
+ end
44
+
45
+ Spec::Matchers.define :have_scheduled_at do |*expected_args|
46
+ match do |actual|
47
+ ResqueSpec.scheduled?(actual, *expected_args)
48
+ end
49
+
50
+ failure_message_for_should do |actual|
51
+ "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
52
+ end
53
+
54
+ failure_message_for_should_not do |actual|
55
+ "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
56
+ end
57
+
58
+ description do
59
+ "have scheduled at the given time the arguments"
60
+ end
61
+ end
62
+
@@ -0,0 +1,53 @@
1
+ require 'resque'
2
+
3
+ module ResqueSpec
4
+ extend self
5
+
6
+ def in_queue?(klass, *args)
7
+ queue_for(klass).any? {|entry| entry[:klass] == klass && entry[:args] == args}
8
+ end
9
+
10
+ def queue_for(klass)
11
+ queues[queue_name(klass)]
12
+ end
13
+
14
+ def queue_name(klass)
15
+ queue_name = klass.instance_variable_get(:@queue) || klass.respond_to?(:queue) && klass.queue
16
+ raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") unless queue_name
17
+ end
18
+
19
+ def queues
20
+ @queues ||= Hash.new {|h,k| h[k] = []}
21
+ end
22
+
23
+ def reset!
24
+ queues.clear
25
+ end
26
+
27
+ module Resque
28
+ def enqueue(klass, *args)
29
+ ResqueSpec.queue_for(klass) << {:klass => klass, :args => args}
30
+ end
31
+ end
32
+ end
33
+
34
+ Resque.extend(ResqueSpec::Resque)
35
+
36
+ Spec::Matchers.define :have_queued do |*expected_args|
37
+ match do |actual|
38
+ ResqueSpec.in_queue?(actual, *expected_args)
39
+ end
40
+
41
+ failure_message_for_should do |actual|
42
+ "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
43
+ end
44
+
45
+ failure_message_for_should_not do |actual|
46
+ "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
47
+ end
48
+
49
+ description do
50
+ "have queued arguments"
51
+ end
52
+ end
53
+
data/lib/resque_spec.rb CHANGED
@@ -1,50 +1,2 @@
1
- require 'resque'
2
-
3
- module ResqueSpec
4
- extend self
5
-
6
- def in_queue?(klass, *args)
7
- queue_for(klass).any? {|entry| entry[:klass] == klass && entry[:args] == args}
8
- end
9
-
10
- def queue_for(klass)
11
- queue_name = klass.instance_variable_get(:@queue) || klass.respond_to?(:queue) && klass.queue
12
- raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") unless queue_name
13
- queues[queue_name]
14
- end
15
-
16
- def queues
17
- @queues ||= Hash.new {|h,k| h[k] = []}
18
- end
19
-
20
- def reset!
21
- queues.clear
22
- end
23
-
24
- module Resque
25
- def enqueue(klass, *args)
26
- ResqueSpec.queue_for(klass) << {:klass => klass, :args => args}
27
- end
28
- end
29
- end
30
-
31
- Resque.extend(ResqueSpec::Resque)
32
-
33
- Spec::Matchers.define :have_queued do |*expected_args|
34
- match do |actual|
35
- ResqueSpec.in_queue?(actual, *expected_args)
36
- end
37
-
38
- failure_message_for_should do |actual|
39
- "expected that #{actual} would have [#{expected_args.join(', ')}] queued"
40
- end
41
-
42
- failure_message_for_should_not do |actual|
43
- "expected that #{actual} would not have [#{expected_args.join(', ')}] queued"
44
- end
45
-
46
- description do
47
- "have queued arguments"
48
- end
49
- end
50
-
1
+ require 'resque_spec/resque_spec'
2
+ require 'resque_spec/resque_scheduler_spec'
data/resque_spec.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque_spec}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Les Hill"]
12
- s.date = %q{2010-06-13}
12
+ s.date = %q{2010-06-24}
13
13
  s.description = %q{RSpec matchers for Resque}
14
14
  s.email = %q{leshill@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,10 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/resque_spec.rb",
29
+ "lib/resque_spec/resque_scheduler_spec.rb",
30
+ "lib/resque_spec/resque_spec.rb",
29
31
  "resque_spec.gemspec",
32
+ "spec/resque_scheduler_spec_spec.rb",
30
33
  "spec/resque_spec_spec.rb",
31
34
  "spec/spec.opts",
32
35
  "spec/spec_helper.rb",
@@ -37,10 +40,11 @@ Gem::Specification.new do |s|
37
40
  s.homepage = %q{http://github.com/leshill/resque_spec}
38
41
  s.rdoc_options = ["--charset=UTF-8"]
39
42
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
43
+ s.rubygems_version = %q{1.3.7}
41
44
  s.summary = %q{RSpec matchers for Resque}
42
45
  s.test_files = [
43
- "spec/resque_spec_spec.rb",
46
+ "spec/resque_scheduler_spec_spec.rb",
47
+ "spec/resque_spec_spec.rb",
44
48
  "spec/spec_helper.rb",
45
49
  "spec/support/account.rb",
46
50
  "spec/support/address.rb",
@@ -51,7 +55,7 @@ Gem::Specification.new do |s|
51
55
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
56
  s.specification_version = 3
53
57
 
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
59
  s.add_runtime_dependency(%q<resque>, [">= 1.6.0"])
56
60
  s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
57
61
  s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ResqueSchedulerSpec" do
4
+ before do
5
+ ResqueSpec.reset!
6
+ end
7
+
8
+ let(:first_name) { 'Les' }
9
+ let(:last_name) { 'Hill' }
10
+ let(:scheduled_at) { Time.now + 5 * 60 }
11
+
12
+ describe "scheduled?" do
13
+ it "returns true if the arguments were queued" do
14
+ Resque.enqueue_at(scheduled_at, Person, first_name, last_name)
15
+ ResqueSpec.scheduled?(Person, scheduled_at, first_name, last_name).should be
16
+ end
17
+
18
+ it "returns false if the arguments were not queued" do
19
+ ResqueSpec.scheduled?(Person, scheduled_at, first_name, last_name).should_not be
20
+ end
21
+ end
22
+
23
+ describe "scheduled_anytime?" do
24
+ it "returns true if the arguments were queued" do
25
+ Resque.enqueue_at(scheduled_at, Person, first_name, last_name)
26
+ ResqueSpec.scheduled_anytime?(Person, first_name, last_name).should be
27
+ end
28
+
29
+ it "returns false if the arguments were not queued" do
30
+ ResqueSpec.scheduled_anytime?(Person, first_name, last_name).should_not be
31
+ end
32
+ end
33
+
34
+ describe "#schedule_for" do
35
+ it "raises if there is no schedule queue defined for a class" do
36
+ expect do
37
+ ResqueSpec.schedule_for(Address)
38
+ end.should raise_exception(::Resque::NoQueueError)
39
+ end
40
+
41
+ it "recognizes a queue defined as a class instance variable" do
42
+ expect do
43
+ ResqueSpec.schedule_for(Person)
44
+ end.should_not raise_exception(::Resque::NoQueueError)
45
+ end
46
+
47
+ it "recognizes a queue defined as a class method" do
48
+ expect do
49
+ ResqueSpec.schedule_for(Account)
50
+ end.should_not raise_exception(::Resque::NoQueueError)
51
+ end
52
+
53
+ it "has an empty array if nothing queued for a class" do
54
+ ResqueSpec.schedule_for(Person).should == []
55
+ end
56
+
57
+ it "allows additions" do
58
+ ResqueSpec.schedule_for(Person) << 'queued'
59
+ ResqueSpec.schedule_for(Person).should_not be_empty
60
+ end
61
+ end
62
+
63
+ describe "Resque" do
64
+ describe "#enqueue_at" do
65
+
66
+ before do
67
+ Resque.enqueue_at(scheduled_at, Person, first_name, last_name)
68
+ end
69
+
70
+ it "adds to the scheduled queue hash" do
71
+ ResqueSpec.schedule_for(Person).should_not be_empty
72
+ end
73
+
74
+ it "sets the klass on the queue" do
75
+ ResqueSpec.schedule_for(Person).first.should include(:klass => Person)
76
+ end
77
+
78
+ it "sets the arguments on the queue" do
79
+ ResqueSpec.schedule_for(Person).first.should include(:args => [first_name, last_name])
80
+ end
81
+
82
+ it "sets the time on the scheduled queue" do
83
+ ResqueSpec.schedule_for(Person).first.should include(:time => scheduled_at)
84
+ end
85
+
86
+ end
87
+ end
88
+
89
+ context "Matchers" do
90
+ before do
91
+ Resque.enqueue_at(scheduled_at, Person, first_name, last_name)
92
+ end
93
+
94
+ describe "#have_scheduled_at" do
95
+ it "returns true if the arguments are found in the queue" do
96
+ Person.should have_scheduled_at(scheduled_at, first_name, last_name)
97
+ end
98
+
99
+ it "returns false if the arguments are not found in the queue" do
100
+ Person.should_not have_scheduled_at(scheduled_at, last_name, first_name)
101
+ end
102
+ end
103
+
104
+ describe "#have_scheduled" do
105
+ it "returns true if the arguments are found in the queue" do
106
+ Person.should have_scheduled(first_name, last_name)
107
+ end
108
+
109
+ it "returns false if the arguments are not found in the queue" do
110
+ Person.should_not have_scheduled(last_name, first_name)
111
+ end
112
+ end
113
+ end
114
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_spec
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
8
  - 2
9
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Les Hill
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-13 00:00:00 -04:00
18
+ date: 2010-06-24 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: resque
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 15
27
30
  segments:
28
31
  - 1
29
32
  - 6
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: jeweler
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 7
41
46
  segments:
42
47
  - 1
43
48
  - 4
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: rspec
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 27
55
62
  segments:
56
63
  - 1
57
64
  - 3
@@ -78,7 +85,10 @@ files:
78
85
  - Rakefile
79
86
  - VERSION
80
87
  - lib/resque_spec.rb
88
+ - lib/resque_spec/resque_scheduler_spec.rb
89
+ - lib/resque_spec/resque_spec.rb
81
90
  - resque_spec.gemspec
91
+ - spec/resque_scheduler_spec_spec.rb
82
92
  - spec/resque_spec_spec.rb
83
93
  - spec/spec.opts
84
94
  - spec/spec_helper.rb
@@ -95,27 +105,32 @@ rdoc_options:
95
105
  require_paths:
96
106
  - lib
97
107
  required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
98
109
  requirements:
99
110
  - - ">="
100
111
  - !ruby/object:Gem::Version
112
+ hash: 3
101
113
  segments:
102
114
  - 0
103
115
  version: "0"
104
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
105
118
  requirements:
106
119
  - - ">="
107
120
  - !ruby/object:Gem::Version
121
+ hash: 3
108
122
  segments:
109
123
  - 0
110
124
  version: "0"
111
125
  requirements: []
112
126
 
113
127
  rubyforge_project:
114
- rubygems_version: 1.3.6
128
+ rubygems_version: 1.3.7
115
129
  signing_key:
116
130
  specification_version: 3
117
131
  summary: RSpec matchers for Resque
118
132
  test_files:
133
+ - spec/resque_scheduler_spec_spec.rb
119
134
  - spec/resque_spec_spec.rb
120
135
  - spec/spec_helper.rb
121
136
  - spec/support/account.rb