Skip to content

Commit

Permalink
Merge pull request resque#524 from tenderlove/mocking
Browse files Browse the repository at this point in the history
eliminate global vars, warnings, and fix test time
  • Loading branch information
hone committed Feb 28, 2012
2 parents 864bdea + 66a8b8b commit 4dbddcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 6 additions & 4 deletions test/test_helper.rb
Expand Up @@ -147,12 +147,14 @@ def with_failure_backend(failure_backend, &block)
class Time
# Thanks, Timecop
class << self
attr_accessor :fake_time

alias_method :now_without_mock_time, :now

def now_with_mock_time
$fake_time || now_without_mock_time
def now
fake_time || now_without_mock_time
end

alias_method :now, :now_with_mock_time
end

self.fake_time = nil
end
22 changes: 14 additions & 8 deletions test/worker_test.rb
Expand Up @@ -355,16 +355,22 @@ def self.exception
end

test "very verbose works in the afternoon" do
require 'time'
$last_puts = ""
$fake_time = Time.parse("15:44:33 2011-03-02")
singleton = class << @worker; self end
singleton.send :define_method, :puts, lambda { |thing| $last_puts = thing }
begin
require 'time'
last_puts = ""
Time.fake_time = Time.parse("15:44:33 2011-03-02")

@worker.very_verbose = true
@worker.log("some log text")
@worker.extend(Module.new {
define_method(:puts) { |thing| last_puts = thing }
})

assert_match /\*\* \[15:44:33 2011-03-02\] \d+: some log text/, $last_puts
@worker.very_verbose = true
@worker.log("some log text")

assert_match /\*\* \[15:44:33 2011-03-02\] \d+: some log text/, last_puts
ensure
Time.fake_time = nil
end
end

test "Will call an after_fork hook after forking" do
Expand Down

0 comments on commit 4dbddcb

Please sign in to comment.