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 ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fake-resque.gemspec
4
+ gemspec
data/README.markdown CHANGED
@@ -8,7 +8,7 @@ and execute any Resque calls synchronously instead of asynchronously.
8
8
  Usage
9
9
  -----
10
10
 
11
- require 'fakefs'
11
+ require 'fake-resque'
12
12
 
13
13
  # That's it.
14
14
 
data/Rakefile CHANGED
@@ -1,60 +1,2 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test')
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
@@ -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
@@ -1,33 +1,29 @@
1
- RealResque = Resque
1
+ require 'fake-resque/faker'
2
2
 
3
3
  module FakeResque
4
+ @@orig_enqueue_method = nil
4
5
  def self.activate!
5
- Object.class_eval do
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
- Object.class_eval do
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
- FakeResque::Resque.block!
17
+ Resque.block!
23
18
  end
24
19
 
25
20
  def self.unblock!
26
- FakeResque::Resque.unblock!
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
@@ -1,2 +1 @@
1
- require 'fake-resque/resque'
2
1
  require 'fake-resque/base'
@@ -1,6 +1,6 @@
1
1
  module FakeResque
2
2
  module Version
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
 
5
5
  def self.to_s
6
6
  VERSION
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
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
- - Jacob Atzen
13
+ - Jacon Atzen
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-19 00:00:00 +01:00
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: jacob@incremental.dk
22
+ email:
23
+ - jacob@incremental.dk
23
24
  executables: []
24
25
 
25
26
  extensions: []
26
27
 
27
- extra_rdoc_files:
28
- - LICENSE
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/resque.rb
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
- - --charset=UTF-8
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.3.6
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.
@@ -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