fake-resque 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +1 -1
- data/Rakefile +2 -60
- data/fake-resque.gemspec +21 -0
- data/lib/fake-resque/base.rb +8 -12
- data/lib/fake-resque/faker.rb +42 -0
- data/lib/fake-resque/safe.rb +0 -1
- data/lib/fake-resque/version.rb +1 -1
- metadata +23 -17
- data/lib/fake-resque/resque.rb +0 -25
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -1,60 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
desc "Run tests"
|
4
|
-
task :test do
|
5
|
-
Dir['test/**/*_test.rb'].each { |file| require file }
|
6
|
-
end
|
7
|
-
|
8
|
-
task :default => [:test, :spec]
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'spec/rake/spectask'
|
12
|
-
|
13
|
-
desc "Run specs"
|
14
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
15
|
-
t.spec_files = FileList["spec/**/*.rb"]
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
puts "Spec task can't be loaded. `gem install rspec`"
|
19
|
-
end
|
20
|
-
|
21
|
-
begin
|
22
|
-
require 'jeweler'
|
23
|
-
|
24
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
|
25
|
-
require 'fake-resque/version'
|
26
|
-
|
27
|
-
Jeweler::Tasks.new do |gemspec|
|
28
|
-
gemspec.name = "fake-resque"
|
29
|
-
gemspec.summary = "A fake resque. Use it in your tests."
|
30
|
-
gemspec.email = "jacob@incremental.dk"
|
31
|
-
gemspec.homepage = "http://github.com/jacobat/fake-resque"
|
32
|
-
gemspec.description = "A fake resque. Use it in your tests."
|
33
|
-
gemspec.authors = ["Jacob Atzen"]
|
34
|
-
gemspec.has_rdoc = false
|
35
|
-
gemspec.version = FakeResque::Version.to_s
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
puts "Jeweler not available."
|
39
|
-
puts "Install it with: gem install jeweler"
|
40
|
-
end
|
41
|
-
|
42
|
-
begin
|
43
|
-
require 'sdoc_helpers'
|
44
|
-
rescue LoadError
|
45
|
-
puts "sdoc support not enabled. Please gem install sdoc-helpers."
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Build a gem"
|
49
|
-
task :gem => [ :gemspec, :build ]
|
50
|
-
|
51
|
-
desc "Push a new version to Gemcutter"
|
52
|
-
task :publish => [ :gemspec, :build ] do
|
53
|
-
abort("Tests failed!") unless system("rake test")
|
54
|
-
system "git tag v#{FakeResque::Version}"
|
55
|
-
system "git push origin v#{FakeResque::Version}"
|
56
|
-
system "git push origin master"
|
57
|
-
system "gem push pkg/fake-resque-#{FakeResque::Version}.gem"
|
58
|
-
system "git clean -fd"
|
59
|
-
exec "rake pages"
|
60
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/fake-resque.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fake-resque/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fake-resque"
|
7
|
+
s.version = FakeResque::Version
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jacon Atzen"]
|
10
|
+
s.email = ["jacob@incremental.dk"]
|
11
|
+
s.homepage = "http://github.com/jacobat/fake-resque"
|
12
|
+
s.summary = %q{A fake resque. Use it in your tests.}
|
13
|
+
s.description = %q{A fake resque. Use it in your tests.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "fake-resque"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/fake-resque/base.rb
CHANGED
@@ -1,33 +1,29 @@
|
|
1
|
-
|
1
|
+
require 'fake-resque/faker'
|
2
2
|
|
3
3
|
module FakeResque
|
4
|
+
@@orig_enqueue_method = nil
|
4
5
|
def self.activate!
|
5
|
-
|
6
|
-
remove_const(:Resque)
|
7
|
-
const_set(:Resque, FakeResque::Resque)
|
8
|
-
end
|
6
|
+
Resque.start_faking!
|
9
7
|
unblock!
|
10
8
|
true
|
11
9
|
end
|
12
10
|
|
13
11
|
def self.deactivate!
|
14
|
-
|
15
|
-
remove_const(:Resque)
|
16
|
-
const_set(:Resque, RealResque)
|
17
|
-
end
|
12
|
+
Resque.stop_faking!
|
18
13
|
true
|
19
14
|
end
|
20
15
|
|
21
16
|
def self.block!
|
22
|
-
|
17
|
+
Resque.block!
|
23
18
|
end
|
24
19
|
|
25
20
|
def self.unblock!
|
26
|
-
|
21
|
+
Resque.unblock!
|
27
22
|
end
|
28
|
-
|
29
23
|
end
|
30
24
|
|
25
|
+
Resque.extend(FakeResque::Faker)
|
26
|
+
|
31
27
|
def FakeResque
|
32
28
|
return ::FakeResque unless block_given?
|
33
29
|
::FakeResque.activate!
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module FakeResque
|
4
|
+
module Faker
|
5
|
+
def fake_push(queue, item)
|
6
|
+
if @forward
|
7
|
+
payload = decode(encode(item))
|
8
|
+
job=Resque::Job.new(queue, payload)
|
9
|
+
begin
|
10
|
+
job.perform
|
11
|
+
rescue Object=>e
|
12
|
+
job.fail(e)
|
13
|
+
# Eat the error because logically it happened in a worker
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def block!
|
19
|
+
@forward = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def unblock!
|
23
|
+
@forward = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def start_faking!
|
27
|
+
replace_push_with(:fake_push)
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop_faking!
|
31
|
+
replace_push_with(:real_push)
|
32
|
+
end
|
33
|
+
|
34
|
+
def replace_push_with(other)
|
35
|
+
(class<< self;self;end).class_eval "alias_method :push, :#{other}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.extended(klass)
|
39
|
+
klass.class_eval "alias_method :real_push, :push"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/fake-resque/safe.rb
CHANGED
data/lib/fake-resque/version.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake-resque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
-
|
13
|
+
- Jacon Atzen
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
18
|
+
date: 2011-09-27 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: A fake resque. Use it in your tests.
|
22
|
-
email:
|
22
|
+
email:
|
23
|
+
- jacob@incremental.dk
|
23
24
|
executables: []
|
24
25
|
|
25
26
|
extensions: []
|
26
27
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
29
|
-
- README.markdown
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
30
|
files:
|
31
|
+
- .gitignore
|
31
32
|
- CONTRIBUTORS
|
33
|
+
- Gemfile
|
32
34
|
- LICENSE
|
33
35
|
- README.markdown
|
34
36
|
- Rakefile
|
37
|
+
- fake-resque.gemspec
|
35
38
|
- lib/fake-resque.rb
|
36
39
|
- lib/fake-resque/base.rb
|
37
|
-
- lib/fake-resque/
|
40
|
+
- lib/fake-resque/faker.rb
|
38
41
|
- lib/fake-resque/safe.rb
|
39
42
|
- lib/fake-resque/version.rb
|
40
|
-
has_rdoc: true
|
41
43
|
homepage: http://github.com/jacobat/fake-resque
|
42
44
|
licenses: []
|
43
45
|
|
44
46
|
post_install_message:
|
45
|
-
rdoc_options:
|
46
|
-
|
47
|
+
rdoc_options: []
|
48
|
+
|
47
49
|
require_paths:
|
48
50
|
- lib
|
49
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
50
53
|
requirements:
|
51
54
|
- - ">="
|
52
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
53
57
|
segments:
|
54
58
|
- 0
|
55
59
|
version: "0"
|
56
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
57
62
|
requirements:
|
58
63
|
- - ">="
|
59
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
60
66
|
segments:
|
61
67
|
- 0
|
62
68
|
version: "0"
|
63
69
|
requirements: []
|
64
70
|
|
65
|
-
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
71
|
+
rubyforge_project: fake-resque
|
72
|
+
rubygems_version: 1.8.5
|
67
73
|
signing_key:
|
68
74
|
specification_version: 3
|
69
75
|
summary: A fake resque. Use it in your tests.
|
data/lib/fake-resque/resque.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module FakeResque
|
2
|
-
class Resque
|
3
|
-
class << self
|
4
|
-
@forward = true
|
5
|
-
def enqueue(klass, *args)
|
6
|
-
if @forward
|
7
|
-
klass.perform(*args)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def block!
|
12
|
-
@forward = false
|
13
|
-
end
|
14
|
-
|
15
|
-
def unblock!
|
16
|
-
@forward = true
|
17
|
-
end
|
18
|
-
|
19
|
-
def redis=(redis)
|
20
|
-
RealResque.redis = redis
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|