spec/spec_helper.rb in rufus-scheduler-3.0.7 vs spec/spec_helper.rb in rufus-scheduler-3.0.8
- old
+ new
@@ -3,17 +3,31 @@
# Specifying rufus-scheduler
#
# Wed Apr 17 06:00:59 JST 2013
#
+puts "RUBY_VERSION: #{RUBY_VERSION}"
+puts "RUBY_PLATFORM: #{RUBY_PLATFORM}"
+
Thread.abort_on_exception = true
-
require 'stringio'
require 'rufus-scheduler'
+#
+# misc helper methods
+def ruby18?
+
+ !! RUBY_VERSION.match(/^1\.8\./)
+end
+
+def jruby?
+
+ !! RUBY_PLATFORM.match(/java/)
+end
+
def local(*args)
Time.local(*args)
end
alias lo local
@@ -21,10 +35,20 @@
def utc(*args)
Time.utc(*args)
end
+def ltz(tz, *args)
+
+ in_zone(tz) { Time.local(*args) }
+end
+
+def ltu(tz, *args)
+
+ in_zone(tz) { Time.local(*args) }.getutc
+end
+
def sleep_until_next_minute
min = Time.now.min
while Time.now.min == min; sleep 2; end
end
@@ -45,11 +69,33 @@
ensure
ENV['TZ'] = prev_tz
end
+def with_chronic(&block)
+ require 'chronic'
+
+ Object.const_set(:Khronic, Chronic) unless defined?(Khronic)
+ Object.const_set(:Chronic, Khronic) unless defined?(Chronic)
+
+ block.call
+
+ensure
+
+ Object.send(:remove_const, :Chronic)
+end
+
+def without_chronic(&block) # for quick counter-tests ;-)
+
+ block.call
+end
+
+
+#
+# matchers
+
#require 'rspec/expectations'
RSpec::Matchers.define :be_within_1s_of do |expected|
match do |actual|
@@ -69,9 +115,12 @@
"expected Time instance, got a #{actual.inspect}"
end
end
end
+
+#
+# configure
#RSpec.configure do |config|
#end