resque_spec 0.1.1

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/.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/.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,4 @@
1
+ source :rubygems
2
+
3
+ gem "resque", ">= 1.9.1"
4
+ gem "rspec", ">= 1.3.0"
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Les Hill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ ResqueSpec
2
+ ==========
3
+
4
+ A simple RSpec and Cucumber matcher for Resque.enqueue, loosely based on
5
+ [http://github.com/justinweiss/resque_unit](resque_unit).
6
+
7
+ Install
8
+ -------
9
+
10
+ Install the gem
11
+
12
+ % gem install resque_spec
13
+
14
+ And update your Gemfile (Not using bundler? Do the necessary thing for
15
+ your app's gem management):
16
+
17
+ group :test do
18
+ gem 'resque_spec'
19
+ end
20
+
21
+ Resque with Specs
22
+ -----------------
23
+
24
+ Given this scenario
25
+
26
+ Given a person
27
+ When I recalculate
28
+ Then the person has calculate queued
29
+
30
+ And I write this spec using the resque_spec matcher
31
+
32
+ describe "#recalculate" do
33
+ before do
34
+ ResqueSpec.reset!
35
+ end
36
+
37
+ it "adds to the calculate to the person queue" do
38
+ person.recalculate
39
+ Person.should have_queued(person.id, :calculate)
40
+ end
41
+ end
42
+
43
+ (And I take note of the `before` block that is using `reset` every spec.)
44
+
45
+ And I might write this as a cucumber step
46
+
47
+ Then /the (\w?) has (\w?) queued/ do |thing, method|
48
+ thing_obj = instance_variable_get("@#{thing}")
49
+ thing_obj.class.should have_queued(thing_obj.id, method.to_sym)
50
+ end
51
+
52
+ Then I write some code to make it pass:
53
+
54
+ class Person
55
+ @queue = :people
56
+
57
+ def recalculate
58
+ Resque.enqueue(Person, id, :calculate)
59
+ end
60
+ end
61
+
62
+
63
+ == Note on Patches/Pull Requests
64
+
65
+ * Fork the project.
66
+ * Make your feature addition or bug fix.
67
+ * Add tests for it. This is important so I don't break it in a
68
+ future version unintentionally.
69
+ * Commit, do not mess with rakefile, version, or history.
70
+ (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)
71
+ * Send me a pull request. Bonus points for topic branches.
72
+
73
+ == Copyright
74
+
75
+ Copyright (c) 2010 Les Hill. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
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.9.1"
14
+ gem.add_development_dependency "rspec", ">= 1.3.0"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "resque_spec #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,50 @@
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
+
@@ -0,0 +1,66 @@
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.1.1"
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-13}
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
+ ".rvmrc",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/resque_spec.rb",
29
+ "resque_spec.gemspec",
30
+ "spec/resque_spec_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "spec/support/account.rb",
34
+ "spec/support/address.rb",
35
+ "spec/support/person.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/leshill/resque_spec}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{RSpec matchers for Resque}
42
+ s.test_files = [
43
+ "spec/resque_spec_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/support/account.rb",
46
+ "spec/support/address.rb",
47
+ "spec/support/person.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<resque>, [">= 1.9.1"])
56
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
57
+ else
58
+ s.add_dependency(%q<resque>, [">= 1.9.1"])
59
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<resque>, [">= 1.9.1"])
63
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
64
+ end
65
+ end
66
+
@@ -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_exception(::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_exception(::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_exception(::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
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'resque_spec'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
+
9
+ Spec::Runner.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 ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Les Hill
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-13 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: resque
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 9
30
+ - 1
31
+ version: 1.9.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 3
44
+ - 0
45
+ version: 1.3.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: RSpec matchers for Resque
49
+ email: leshill@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.md
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - .rvmrc
61
+ - Gemfile
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - VERSION
66
+ - lib/resque_spec.rb
67
+ - resque_spec.gemspec
68
+ - spec/resque_spec_spec.rb
69
+ - spec/spec.opts
70
+ - spec/spec_helper.rb
71
+ - spec/support/account.rb
72
+ - spec/support/address.rb
73
+ - spec/support/person.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/leshill/resque_spec
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.6
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: RSpec matchers for Resque
104
+ test_files:
105
+ - spec/resque_spec_spec.rb
106
+ - spec/spec_helper.rb
107
+ - spec/support/account.rb
108
+ - spec/support/address.rb
109
+ - spec/support/person.rb