test/test_helper.rb in resque-scheduler-2.3.1 vs test/test_helper.rb in resque-scheduler-2.4.0
- old
+ new
@@ -1,45 +1,40 @@
-
# Pretty much copied this file from the resque test_helper since we want
# to do all the same stuff
dir = File.dirname(File.expand_path(__FILE__))
require 'rubygems'
+require 'bundler/setup'
+
+require 'simplecov' unless RUBY_VERSION < '1.9'
+
require 'test/unit'
require 'mocha/setup'
require 'resque'
+
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__)) + '/../lib'
require 'resque_scheduler'
require 'resque_scheduler/server'
-#
-# make sure we can run redis
-#
-
-if !system("which redis-server")
- puts '', "** can't find `redis-server` in your path"
- puts "** try running `sudo rake install`"
- abort ''
+unless ENV['RESQUE_SCHEDULER_DISABLE_TEST_REDIS_SERVER']
+ # Start our own Redis when the tests start. RedisInstance will take care of
+ # starting and stopping.
+ require File.expand_path('../support/redis_instance', __FILE__)
+ RedisInstance.run!
end
-
-# Start our own Redis when the tests start. RedisInstance will take care of
-# starting and stopping.
-require File.dirname(__FILE__) + '/support/redis_instance'
-RedisInstance.run!
-
at_exit do
next if $!
if defined?(MiniTest)
exit_code = MiniTest::Unit.new.run(ARGV)
else
exit_code = Test::Unit::AutoRunner.run
end
- exit exit_code
+ exit(exit_code || 0)
end
##
# test/spec/mini 3
# http://gist.github.com/25455
@@ -58,10 +53,18 @@
end
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
klass.class_eval(&block)
end
+unless defined?(Rails)
+ module Rails
+ class << self
+ attr_accessor :env
+ end
+ end
+end
+
class FakeCustomJobClass
def self.scheduled(queue, klass, *args); end
end
class FakeCustomJobClassEnqueueAt
@@ -90,11 +93,35 @@
end
end
JobWithoutParams = Class.new(JobWithParams)
+%w(
+ APP_NAME
+ DYNAMIC_SCHEDULE
+ LOGFILE
+ LOGFORMAT
+ MUTE
+ RAILS_ENV
+ RESQUE_SCHEDULER_INTERVAL
+ VERBOSE
+).each do |envvar|
+ ENV[envvar] = nil
+end
+
def nullify_logger
- Resque::Scheduler.mute = nil
- Resque::Scheduler.verbose = nil
- Resque::Scheduler.logfile = nil
- Resque::Scheduler.logger = nil
+ Resque::Scheduler.configure do |c|
+ c.mute = nil
+ c.verbose = nil
+ c.logfile = nil
+ c.logger = nil
+ end
+
+ ENV['LOGFILE'] = nil
end
+
+def restore_devnull_logfile
+ nullify_logger
+ ENV['LOGFILE'] = '/dev/null'
+end
+
+restore_devnull_logfile