resque_spec 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .bundle
21
+
22
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm gemset use resque_spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem "jeweler", ">= 1.4.0"
4
+ gem "resque", ">= 1.6.0"
5
+ gem "rspec", ">= 2.0.0.beta.14"
data/README.md CHANGED
@@ -2,9 +2,11 @@ ResqueSpec
2
2
  ==========
3
3
 
4
4
  A simple RSpec and Cucumber matcher for Resque.enqueue and Resque.enqueue_at (from `ResqueScheduler`), loosely based on
5
- [http://github.com/justinweiss/resque_unit](http://github.com/justinweiss/resque_unit).
5
+ [http://github.com/justinweiss/resque_unit](resque_unit).
6
6
 
7
- This should work with Resque v1.6.0 and up and RSpec v1.3.0 and up.
7
+ This should work with `Resque v1.6.0` and up and `RSpec v2.0.0.beta.12` and up.
8
+
9
+ If you are using `RSpec ~> 1.3.0`, you should use version `~> 0.2.0`.
8
10
 
9
11
  Install
10
12
  -------
data/Rakefile CHANGED
@@ -1,18 +1,36 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- require 'spec/rake/spectask'
5
- Spec::Rake::SpecTask.new(:spec) do |spec|
6
- spec.libs << 'lib' << 'spec'
7
- spec.spec_files = FileList['spec/**/*_spec.rb']
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "resque_spec"
8
+ gem.summary = %Q{RSpec matchers for Resque}
9
+ gem.description = %Q{RSpec matchers for Resque}
10
+ gem.email = "leshill@gmail.com"
11
+ gem.homepage = "http://github.com/leshill/resque_spec"
12
+ gem.authors = ["Les Hill"]
13
+ gem.add_dependency "resque", ">= 1.6.0"
14
+ gem.add_dependency "rspec", ">= 2.0.0.beta.12"
15
+ gem.add_development_dependency "jeweler", ">= 1.4.0"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
8
20
  end
9
21
 
10
- Spec::Rake::SpecTask.new(:rcov) do |spec|
11
- spec.libs << 'lib' << 'spec'
22
+ require 'rspec/core/rake_task'
23
+ RSpec::Core::RakeTask.new(:spec) do |spec|
24
+ spec.pattern = 'spec/**/*_spec.rb'
25
+ end
26
+
27
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
12
28
  spec.pattern = 'spec/**/*_spec.rb'
13
29
  spec.rcov = true
14
30
  end
15
31
 
32
+ task :spec => :check_dependencies
33
+
16
34
  task :default => :spec
17
35
 
18
36
  require 'rake/rdoctask'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  Resque.extend(ResqueSpec::ResqueScheduler)
26
26
 
27
- Spec::Matchers.define :have_scheduled do |*expected_args|
27
+ RSpec::Matchers.define :have_scheduled do |*expected_args|
28
28
  match do |actual|
29
29
  ResqueSpec.scheduled_anytime?(actual, *expected_args)
30
30
  end
@@ -42,7 +42,7 @@ Spec::Matchers.define :have_scheduled do |*expected_args|
42
42
  end
43
43
  end
44
44
 
45
- Spec::Matchers.define :have_scheduled_at do |*expected_args|
45
+ RSpec::Matchers.define :have_scheduled_at do |*expected_args|
46
46
  match do |actual|
47
47
  ResqueSpec.scheduled?(actual, *expected_args)
48
48
  end
@@ -1,5 +1,5 @@
1
+ require 'rspec'
1
2
  require 'resque'
2
- require 'spec'
3
3
 
4
4
  module ResqueSpec
5
5
  extend self
@@ -13,9 +13,8 @@ module ResqueSpec
13
13
  end
14
14
 
15
15
  def queue_name(klass)
16
- name_from_instance_var(klass) or
17
- name_from_queue_accessor(klass) or
18
- raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.")
16
+ queue_name = klass.instance_variable_get(:@queue) || klass.respond_to?(:queue) && klass.queue
17
+ raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") unless queue_name
19
18
  end
20
19
 
21
20
  def queues
@@ -31,21 +30,11 @@ module ResqueSpec
31
30
  ResqueSpec.queue_for(klass) << {:klass => klass, :args => args}
32
31
  end
33
32
  end
34
-
35
- private
36
-
37
- def name_from_instance_var(klass)
38
- klass.instance_variable_get(:@queue)
39
- end
40
-
41
- def name_from_queue_accessor(klass)
42
- klass.respond_to?(:queue) and klass.queue
43
- end
44
33
  end
45
34
 
46
35
  Resque.extend(ResqueSpec::Resque)
47
36
 
48
- Spec::Matchers.define :have_queued do |*expected_args|
37
+ RSpec::Matchers.define :have_queued do |*expected_args|
49
38
  match do |actual|
50
39
  ResqueSpec.in_queue?(actual, *expected_args)
51
40
  end
data/lib/resque_spec.rb CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'resque_spec/resque_spec'
2
2
  require 'resque_spec/resque_scheduler_spec'
3
+
4
+ module ResqueSpec
5
+ VERSION = '0.3.0'.freeze
6
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{resque_spec}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Les Hill"]
12
+ s.date = %q{2010-06-29}
13
+ s.description = %q{RSpec matchers for Resque}
14
+ s.email = %q{leshill@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ ".rvmrc",
24
+ "Gemfile",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/resque_spec.rb",
30
+ "lib/resque_spec/resque_scheduler_spec.rb",
31
+ "lib/resque_spec/resque_spec.rb",
32
+ "resque_spec.gemspec",
33
+ "spec/resque_scheduler_spec_spec.rb",
34
+ "spec/resque_spec_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "spec/support/account.rb",
37
+ "spec/support/address.rb",
38
+ "spec/support/person.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/leshill/resque_spec}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.7}
44
+ s.summary = %q{RSpec matchers for Resque}
45
+ s.test_files = [
46
+ "spec/resque_scheduler_spec_spec.rb",
47
+ "spec/resque_spec_spec.rb",
48
+ "spec/spec_helper.rb",
49
+ "spec/support/account.rb",
50
+ "spec/support/address.rb",
51
+ "spec/support/person.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<resque>, [">= 1.6.0"])
60
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
61
+ s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
62
+ else
63
+ s.add_dependency(%q<resque>, [">= 1.6.0"])
64
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
65
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<resque>, [">= 1.6.0"])
69
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
70
+ s.add_dependency(%q<jeweler>, [">= 1.4.0"])
71
+ end
72
+ end
73
+
@@ -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_error(::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_error(::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_error(::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
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ResqueSpec" do
4
+ before do
5
+ ResqueSpec.reset!
6
+ end
7
+
8
+ let(:first_name) { 'Les' }
9
+ let(:last_name) { 'Hill' }
10
+
11
+ describe "#queue_for" do
12
+ it "raises if there is no queue defined for a class" do
13
+ expect do
14
+ ResqueSpec.queue_for(Address)
15
+ end.should raise_error(::Resque::NoQueueError)
16
+ end
17
+
18
+ it "recognizes a queue defined as a class instance variable" do
19
+ expect do
20
+ ResqueSpec.queue_for(Person)
21
+ end.should_not raise_error(::Resque::NoQueueError)
22
+ end
23
+
24
+ it "recognizes a queue defined as a class method" do
25
+ expect do
26
+ ResqueSpec.queue_for(Account)
27
+ end.should_not raise_error(::Resque::NoQueueError)
28
+ end
29
+
30
+ it "has an empty array if nothing queued for a class" do
31
+ ResqueSpec.queue_for(Person).should == []
32
+ end
33
+
34
+ it "allows additions" do
35
+ ResqueSpec.queue_for(Person) << 'queued'
36
+ ResqueSpec.queue_for(Person).should_not be_empty
37
+ end
38
+ end
39
+
40
+ describe "#reset!" do
41
+ it "clears the queues" do
42
+ ResqueSpec.queue_for(Person) << 'queued'
43
+ ResqueSpec.reset!
44
+ ResqueSpec.queues.should be_empty
45
+ end
46
+ end
47
+
48
+ describe "in_queue?" do
49
+
50
+ it "returns true if the arguments were queued" do
51
+ Resque.enqueue(Person, first_name, last_name)
52
+ ResqueSpec.in_queue?(Person, first_name, last_name).should be
53
+ end
54
+
55
+ it "returns false if the arguments were not queued" do
56
+ ResqueSpec.in_queue?(Person, first_name, last_name).should_not be
57
+ end
58
+
59
+ end
60
+
61
+ describe "Resque" do
62
+ describe "#enqueue" do
63
+
64
+ before do
65
+ Resque.enqueue(Person, first_name, last_name)
66
+ end
67
+
68
+ it "adds to the queue hash" do
69
+ ResqueSpec.queue_for(Person).should_not be_empty
70
+ end
71
+
72
+ it "sets the klass on the queue" do
73
+ ResqueSpec.queue_for(Person).first.should include(:klass => Person)
74
+ end
75
+
76
+ it "sets the arguments on the queue" do
77
+ ResqueSpec.queue_for(Person).first.should include(:args => [first_name, last_name])
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ context "Matchers" do
84
+ before do
85
+ Resque.enqueue(Person, first_name, last_name)
86
+ end
87
+
88
+ describe "#have_queued" do
89
+ it "returns true if the arguments are found in the queue" do
90
+ Person.should have_queued(first_name, last_name)
91
+ end
92
+
93
+ it "returns false if the arguments are not found in the queue" do
94
+ Person.should_not have_queued(last_name, first_name)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rspec'
4
+ require 'rspec/autorun'
5
+ require 'resque_spec'
6
+
7
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ end
@@ -0,0 +1,5 @@
1
+ class Account
2
+ def self.queue
3
+ :people
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ class Address
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Person
2
+ @queue = :people
3
+ end
metadata CHANGED
@@ -1,73 +1,140 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque_spec
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Les Hill
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-09-10 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2010-06-29 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: resque
16
- requirement: &70315036469640 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 6
33
+ - 0
21
34
  version: 1.6.0
22
35
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70315036469640
25
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
26
38
  name: rspec
27
- requirement: &70315036469000 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
28
41
  none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: 1.3.0
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 62196475
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ - beta
51
+ - 12
52
+ version: 2.0.0.beta.12
33
53
  type: :runtime
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
34
57
  prerelease: false
35
- version_requirements: *70315036469000
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 7
64
+ segments:
65
+ - 1
66
+ - 4
67
+ - 0
68
+ version: 1.4.0
69
+ type: :development
70
+ version_requirements: *id003
36
71
  description: RSpec matchers for Resque
37
72
  email: leshill@gmail.com
38
73
  executables: []
74
+
39
75
  extensions: []
40
- extra_rdoc_files: []
41
- files:
42
- - lib/resque_spec/resque_scheduler_spec.rb
43
- - lib/resque_spec/resque_spec.rb
44
- - lib/resque_spec/version.rb
45
- - lib/resque_spec.rb
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE
79
+ - README.md
80
+ files:
81
+ - .document
82
+ - .gitignore
83
+ - .rspec
84
+ - .rvmrc
85
+ - Gemfile
46
86
  - LICENSE
47
87
  - README.md
48
88
  - Rakefile
89
+ - VERSION
90
+ - lib/resque_spec.rb
91
+ - lib/resque_spec/resque_scheduler_spec.rb
92
+ - lib/resque_spec/resque_spec.rb
93
+ - resque_spec.gemspec
94
+ - spec/resque_scheduler_spec_spec.rb
95
+ - spec/resque_spec_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/support/account.rb
98
+ - spec/support/address.rb
99
+ - spec/support/person.rb
100
+ has_rdoc: true
49
101
  homepage: http://github.com/leshill/resque_spec
50
102
  licenses: []
103
+
51
104
  post_install_message:
52
- rdoc_options: []
53
- require_paths:
105
+ rdoc_options:
106
+ - --charset=UTF-8
107
+ require_paths:
54
108
  - lib
55
- required_ruby_version: !ruby/object:Gem::Requirement
109
+ required_ruby_version: !ruby/object:Gem::Requirement
56
110
  none: false
57
- requirements:
58
- - - ! '>='
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
119
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: 1.3.6
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
67
127
  requirements: []
128
+
68
129
  rubyforge_project:
69
- rubygems_version: 1.8.10
130
+ rubygems_version: 1.3.7
70
131
  signing_key:
71
132
  specification_version: 3
72
133
  summary: RSpec matchers for Resque
73
- test_files: []
134
+ test_files:
135
+ - spec/resque_scheduler_spec_spec.rb
136
+ - spec/resque_spec_spec.rb
137
+ - spec/spec_helper.rb
138
+ - spec/support/account.rb
139
+ - spec/support/address.rb
140
+ - spec/support/person.rb
@@ -1,3 +0,0 @@
1
- module ResqueSpec
2
- VERSION = '0.2.3'
3
- end