que-testing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88494919546cd56dce9387d4dc3ba5506c8805e3
4
+ data.tar.gz: 172915e6c25083e5f3ab4eb3ffbce38e1c202efa
5
+ SHA512:
6
+ metadata.gz: c15b162102303df955b2ee8cfe7c6041ce04efa35f525610a4bfb596a71533cdfe50d0acc2cf8e067a2d8119acb61eba6a47a07a92bd13bbffd6e0c52d4d9242
7
+ data.tar.gz: 5dc3774a85cc4638a93f5634099e9f8763300656e5e591baabf5539252d2b717fe95c7b145e3c516810f5430a6a7be8dad2349a04ef4b7c9a2702bf2f7a4c983
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor/bundle
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ - jruby
7
+ notifications:
8
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2014, Jason Staten
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its contributors
15
+ may be used to endorse or promote products derived from this software
16
+ without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28
+ DAMAGE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # que-testing
2
+
3
+ Testing support for the [Que](https://github.com/chanks/que) queue
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'que-testing'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install que-testing
20
+
21
+ ## Usage
22
+
23
+ In your test, `require 'que/testing'` and enqueue jobs as normal. Jobs are
24
+ stored under a `MyJob.jobs` array. Because they're static, the stored jobs
25
+ should be cleared between test runs.
26
+
27
+ ```ruby
28
+ require "que/testing"
29
+
30
+ describe "Testing" do
31
+ after { MyJob.jobs.clear }
32
+
33
+ it "Stores a job" do
34
+ MyJob.enqueue("foo")
35
+
36
+ js = MyJob.jobs
37
+ js.length.must_equal 1
38
+ js.first["args"].must_equal ["foo"]
39
+ js.first["job_class"].must_equal ["MyJob"]
40
+ end
41
+ end
42
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs = ['spec', 'lib']
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ end
@@ -0,0 +1,6 @@
1
+ require "que"
2
+ require "que/testing/que_ext"
3
+ require "que/testing/adapter"
4
+ require "que/testing/version"
5
+
6
+ Que.adapter = Que::Testing::Adapter.new
@@ -0,0 +1,28 @@
1
+ module Que
2
+ module Testing
3
+ class JobParams < Struct.new(:queue, :priority, :run_at, :job_class, :args)
4
+ end
5
+
6
+ class Adapter
7
+ def checkout(&block)
8
+ end
9
+
10
+ def execute(command, params = [])
11
+ return [] unless command == :insert_job
12
+
13
+ job = JobParams.new(*params)
14
+ klass = class_for(job.job_class)
15
+ klass.jobs << job
16
+ params
17
+ end
18
+
19
+ def wake_worker_after_commit
20
+ false
21
+ end
22
+
23
+ def class_for(str)
24
+ str.split('::').reduce(Object, &:const_get)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Que
2
+ class Job
3
+ def self.jobs
4
+ @jobs ||= []
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Que
2
+ module Testing
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'que/testing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "que-testing"
8
+ spec.version = Que::Testing::VERSION
9
+ spec.authors = ["Jason Staten"]
10
+ spec.email = ["jstaten07@gmail.com"]
11
+ spec.summary = %q{Testing support for the Que queue}
12
+ spec.description = %q{Testing support fot the Que queue}
13
+ spec.homepage = "https://github.com/statianzo/que-testing"
14
+ spec.license = "BSD"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "que"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.4"
26
+ end
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require "que/testing"
3
+ require "minitest/autorun"
4
+
5
+ class CustomFilter
6
+ def self.filter(bt)
7
+ return ['No backtrace'] unless bt
8
+
9
+ new_bt = bt.take_while { |line| line !~ %r{minitest} }
10
+ new_bt = bt.select { |line| line !~ %r{minitest} } if new_bt.empty?
11
+ new_bt = bt.dup if new_bt.empty?
12
+
13
+ new_bt
14
+ end
15
+ end
16
+
17
+ Minitest.backtrace_filter = CustomFilter
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ class TestJob < Que::Job
4
+ def run(a, b)
5
+ a * b
6
+ end
7
+ end
8
+
9
+ describe Que::Testing do
10
+ after { TestJob.jobs.clear }
11
+
12
+ it "stashes calls" do
13
+ TestJob.jobs.count.must_equal 0
14
+ TestJob.enqueue 1, 2
15
+ TestJob.jobs.count.must_equal 1
16
+ TestJob.jobs.first['args'].must_equal [1,2]
17
+ TestJob.jobs.first.job_class.must_equal "TestJob"
18
+ time = Time.now
19
+ TestJob.enqueue 1, 2, run_at: time
20
+ TestJob.jobs.last.run_at.must_equal time
21
+ end
22
+
23
+ it "responds empty for non-insert commands" do
24
+ stats = Que.job_stats
25
+ stats.must_be_empty
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: que-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Staten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: que
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.4'
69
+ description: Testing support fot the Que queue
70
+ email:
71
+ - jstaten07@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/que/testing.rb
83
+ - lib/que/testing/adapter.rb
84
+ - lib/que/testing/que_ext.rb
85
+ - lib/que/testing/version.rb
86
+ - que-testing.gemspec
87
+ - spec/spec_helper.rb
88
+ - spec/testing_spec.rb
89
+ homepage: https://github.com/statianzo/que-testing
90
+ licenses:
91
+ - BSD
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Testing support for the Que queue
113
+ test_files:
114
+ - spec/spec_helper.rb
115
+ - spec/testing_spec.rb