resque_unit_without_mock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/resque_unit_without_mock.rb +21 -0
- data/lib/resque_unit_without_mock/resque_assertions.rb +32 -0
- data/lib/resque_unit_without_mock/resque_helpers.rb +27 -0
- data/lib/resque_unit_without_mock/scheduler.rb +29 -0
- data/lib/resque_unit_without_mock/scheduler_assertions.rb +19 -0
- data/lib/resque_unit_without_mock/version.rb +3 -0
- data/lib/resque_unit_without_mock_scheduler.rb +14 -0
- data/resque_unit_without_mock.gemspec +31 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fbfdabc7af3a22de5e40c2119246b035acfdbd5d08f561ec2e77aeb231fd590c
|
4
|
+
data.tar.gz: 4a70f374c92a06b79dc79026b00163707d04cb24a505f56824ec92719ce2a043
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 229d1222c929a7861cecaace68aad49761ad4a98019e77782cdbdbd96c18c3085ead46f3ff036714bda8e4c0b8de537111f486743baa75898236d12c877b071c
|
7
|
+
data.tar.gz: 055350c0fd3319ca38dc6570292039c401698dd19a991d193cca3c73f6a1bb46824baf35e334efe23996b7b023b0adb1d15901a08cde072af280e000236c1566
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
resque_unit_without_mock (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
minitest-hooks (1.5.0)
|
11
|
+
minitest (> 5.3)
|
12
|
+
mono_logger (1.1.0)
|
13
|
+
multi_json (1.13.1)
|
14
|
+
mustermann (1.0.3)
|
15
|
+
rack (2.0.6)
|
16
|
+
rack-protection (2.0.5)
|
17
|
+
rack
|
18
|
+
rake (10.5.0)
|
19
|
+
redis (4.1.0)
|
20
|
+
redis-namespace (1.6.0)
|
21
|
+
redis (>= 3.0.4)
|
22
|
+
resque (2.0.0)
|
23
|
+
mono_logger (~> 1.0)
|
24
|
+
multi_json (~> 1.0)
|
25
|
+
redis-namespace (~> 1.6)
|
26
|
+
sinatra (>= 0.9.2)
|
27
|
+
vegas (~> 0.1.2)
|
28
|
+
sinatra (2.0.5)
|
29
|
+
mustermann (~> 1.0)
|
30
|
+
rack (~> 2.0)
|
31
|
+
rack-protection (= 2.0.5)
|
32
|
+
tilt (~> 2.0)
|
33
|
+
tilt (2.0.9)
|
34
|
+
vegas (0.1.11)
|
35
|
+
rack (>= 1.0.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 1.17)
|
42
|
+
minitest (~> 5.0)
|
43
|
+
minitest-hooks
|
44
|
+
rake (~> 10.0)
|
45
|
+
resque
|
46
|
+
resque_unit_without_mock!
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 jiikko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# ResqueUnitWithoutMock
|
2
|
+
現物redisにを使いながらresque_unitとほぼ同じIFのメソッドを提供するgemです。
|
3
|
+
このgemを使うと、resque_unitを使っていたけど実物redisを使うテストに切り替える時に既存テストをほぼ維持したまま移行が可能です。
|
4
|
+
minitestのみサポートしています。(please pull request for support rspec)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'resque_unit_without_mock', group: :test
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
### resque_unitとの違い
|
20
|
+
resque_unitで提供していた `Resque.queues` は `Resque.queued` になっています。
|
21
|
+
|
22
|
+
### `Resque.reset!` はプロジェクト内で再定義してください
|
23
|
+
専用のredis-serverプロセスを使っているなら `flushdb`でいいですが、
|
24
|
+
相乗りしているredis-serverの場合は https://gist.github.com/aserafin/6916037 みたいな感じで初期化するとよいでしょう。
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# example
|
28
|
+
module ResqueHelpersExt
|
29
|
+
def reset!
|
30
|
+
Resque.data_store.redis.select(ENV['TEST_ENV_NUMBER'].to_i + 1)
|
31
|
+
Resque.data_store.redis.flushdb
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
Resque.singleton_class.prepend(ResqueHelpersExt)
|
36
|
+
```
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "resque_unit_without_mock"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module ResqueUnitWithoutMock
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'resque'
|
5
|
+
require 'resque_unit_without_mock/version'
|
6
|
+
require 'resque_unit_without_mock/resque_helpers'
|
7
|
+
require 'resque_unit_without_mock/resque_assertions'
|
8
|
+
|
9
|
+
Resque.include(ResqueUnitWithoutMock::ResqueHelpers)
|
10
|
+
|
11
|
+
if defined?(Test::Unit::TestCase)
|
12
|
+
Test::Unit::TestCase.include(ResqueUnitWithoutMock::ResqueAssertions)
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(MiniTest::Unit::TestCase)
|
16
|
+
MiniTest::Unit::TestCase.include(ResqueUnitWithoutMock::ResqueAssertions)
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(Minitest::Test)
|
20
|
+
Minitest::Test.include(ResqueUnitWithoutMock::ResqueAssertions)
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "minitest"
|
2
|
+
|
3
|
+
module ResqueUnitWithoutMock::ResqueAssertions
|
4
|
+
def assert_queued(klass, args = nil, &block)
|
5
|
+
queue_name = Resque.queue_for(klass)
|
6
|
+
queue = Resque.queued(queue_name).map{|x| JSON.parse(x) }
|
7
|
+
assert(
|
8
|
+
in_queue?(queue, klass, args),
|
9
|
+
"#{klass}#{args ? " with #{args.inspect}" : ""} should have been queued in #{queue_name}: #{queue.inspect}.",
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_not_queued(klass, args = nil, &block)
|
14
|
+
queue_name = Resque.queue_for(klass)
|
15
|
+
queue = Resque.queued(queue_name).map{|x| JSON.parse(x) }
|
16
|
+
assert(
|
17
|
+
!in_queue?(queue, klass, args),
|
18
|
+
"#{klass}#{args ? " with #{args.inspect}" : ""} should not have been queued in #{queue_name}.",
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def in_queue?(queue, klass, args = nil)
|
25
|
+
!matching_jobs(queue, klass, args).empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def matching_jobs(queue, klass, args = nil)
|
29
|
+
normalized_args = Resque.decode(Resque.encode(args)) if args
|
30
|
+
queue.select {|e| e["class"] == klass.to_s && (!args || e["args"] == normalized_args )}
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ResqueUnitWithoutMock::ResqueHelpers
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def reset!
|
8
|
+
end
|
9
|
+
|
10
|
+
def run!(queue_name=:normal)
|
11
|
+
jobs = []
|
12
|
+
loop do
|
13
|
+
job = Resque.reserve(queue_name)
|
14
|
+
job ? (jobs << job) : break
|
15
|
+
end
|
16
|
+
jobs.each(&:perform)
|
17
|
+
end
|
18
|
+
|
19
|
+
def queued(queue_name=:normal)
|
20
|
+
Resque.redis.lrange("queue:#{queue_name}", 0, -1)
|
21
|
+
end
|
22
|
+
|
23
|
+
def queue_for(klass)
|
24
|
+
klass.instance_variable_get(:@queue) || (klass.respond_to?(:queue) && klass.queue)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ResqueUnitWithoutMock::Scheduler
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(ClassMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# resque_unit前提で書かれた既存テストではResque.enqueue_atするとすぐにエンキューしながら、
|
8
|
+
# タイムスタンプを確認している.
|
9
|
+
# 実物Redisを使うにあたって同じ振る舞いにしたいのでクラス変数を使ってresque_unitと同じことを実現する.
|
10
|
+
def enqueue_at(timestamp, klass, *args)
|
11
|
+
queue = queue_for(klass)
|
12
|
+
@@enqueue_ats ||= {}
|
13
|
+
@@enqueue_ats[queue] ||= []
|
14
|
+
@@enqueue_ats[queue] << { timestamp: timestamp, klass: klass, args: args }
|
15
|
+
Resque.enqueue(klass, *args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def enqueue_ats(queue)
|
19
|
+
@@enqueue_ats ||= {}
|
20
|
+
@@enqueue_ats[queue] || []
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset!
|
24
|
+
@@enqueue_ats = {}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Resque.include(ResqueUnitWithoutMock::Scheduler)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ResqueUnitWithoutMock::SchedulerAssertions
|
2
|
+
def assert_queued_at(expected_timestamp, klass)
|
3
|
+
queue = Resque.queue_for(klass)
|
4
|
+
result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass }
|
5
|
+
assert(
|
6
|
+
result,
|
7
|
+
"#{klass} should have been queued in #{Resque.enqueue_ats(queue)} before #{expected_timestamp}"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_not_queued_at(expected_timestamp, klass)
|
12
|
+
queue = Resque.queue_for(klass)
|
13
|
+
result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass }
|
14
|
+
assert(
|
15
|
+
!result,
|
16
|
+
"#{klass} should not have been queued in #{Resque.enqueue_ats(queue)} before #{expected_timestamp}"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'resque_unit_without_mock/scheduler'
|
2
|
+
require 'resque_unit_without_mock/scheduler_assertions'
|
3
|
+
|
4
|
+
if defined?(Test::Unit::TestCase)
|
5
|
+
Test::Unit::TestCase.include(ResqueUnitWithoutMock::SchedulerAssertions)
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(MiniTest::Unit::TestCase)
|
9
|
+
MiniTest::Unit::TestCase.include(ResqueUnitWithoutMock::SchedulerAssertions)
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Minitest::Test)
|
13
|
+
Minitest::Test.include(ResqueUnitWithoutMock::SchedulerAssertions)
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "resque_unit_without_mock/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "resque_unit_without_mock"
|
8
|
+
spec.version = ResqueUnitWithoutMock::VERSION
|
9
|
+
spec.authors = ["jiikko"]
|
10
|
+
spec.email = ["n905i.1214@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{resque_unit(without mock)}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/jiikko/resque_unit_without_mock"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "minitest-hooks"
|
30
|
+
spec.add_development_dependency "resque"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque_unit_without_mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiikko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-hooks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: resque
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: resque_unit(without mock)
|
84
|
+
email:
|
85
|
+
- n905i.1214@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/resque_unit_without_mock.rb
|
100
|
+
- lib/resque_unit_without_mock/resque_assertions.rb
|
101
|
+
- lib/resque_unit_without_mock/resque_helpers.rb
|
102
|
+
- lib/resque_unit_without_mock/scheduler.rb
|
103
|
+
- lib/resque_unit_without_mock/scheduler_assertions.rb
|
104
|
+
- lib/resque_unit_without_mock/version.rb
|
105
|
+
- lib/resque_unit_without_mock_scheduler.rb
|
106
|
+
- resque_unit_without_mock.gemspec
|
107
|
+
homepage: https://github.com/jiikko/resque_unit_without_mock
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.7.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: resque_unit(without mock)
|
131
|
+
test_files: []
|