test/test_utils.rb in tzinfo-1.1.0 vs test/test_utils.rb in tzinfo-1.2.0
- old
+ new
@@ -1,27 +1,5 @@
-#--
-# Copyright (c) 2008-2013 Philip Ross
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#++
-
TESTS_DIR = File.expand_path(File.dirname(__FILE__)).untaint
TZINFO_LIB_DIR = File.expand_path(File.join(TESTS_DIR, '..', 'lib'))
TZINFO_TEST_DATA_DIR = File.join(TESTS_DIR, 'tzinfo-data')
TZINFO_TEST_ZONEINFO_DIR = File.join(TESTS_DIR, 'zoneinfo')
@@ -29,11 +7,11 @@
# tzinfo-data contains a cut down copy of tzinfo-data for use in the tests.
# Add it to the load path.
$:.unshift(TZINFO_TEST_DATA_DIR) unless $:.include?(TZINFO_TEST_DATA_DIR)
-require 'test/unit'
+require 'minitest/autorun'
require 'tzinfo'
require 'fileutils'
require 'rbconfig'
module TestUtils
@@ -44,11 +22,11 @@
def self.prepare_test_zoneinfo_dir
ZONEINFO_SYMLINKS.each do |file, target|
path = File.join(TZINFO_TEST_ZONEINFO_DIR, file)
- File.delete(path) if File.exists?(path)
+ File.delete(path) if File.exist?(path)
begin
FileUtils.ln_s(target, path)
rescue NotImplementedError
target_path = File.join(TZINFO_TEST_ZONEINFO_DIR, target)
@@ -86,16 +64,14 @@
thread.join
end
end
- def assert_array_same_items(expected, actual, message = nil)
- full_message = build_message(message, "<?> expected but was <?>.", expected, actual)
-
- assert_block(full_message) do
- (expected.size == actual.size) && (expected - actual == [])
- end
+ def assert_array_same_items(expected, actual, msg = nil)
+ full_message = message(msg, '') { diff(expected, actual) }
+ condition = (expected.size == actual.size) && (expected - actual == [])
+ assert(condition, full_message)
end
def assert_sub_process_returns(expected_lines, code, extra_load_path = [], required = ['tzinfo'])
ruby = File.join(RbConfig::CONFIG['bindir'],
RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'])
@@ -131,6 +107,26 @@
actual_lines = process.readlines
actual_lines = actual_lines.collect {|l| l.chomp}
assert_equal(expected_lines, actual_lines)
end
end
+
+ def assert_nothing_raised(msg = nil)
+ begin
+ yield
+ rescue => e
+ full_message = message(msg) { exception_details(e, 'Exception raised: ') }
+ assert(false, full_message)
+ end
+ end
end
+
+
+# JRuby 1.7.5 to 1.7.9 consider DateTime instances that differ by less than
+# 1 millisecond to be equivalent (https://github.com/jruby/jruby/issues/1311).
+#
+# A few test cases compare at a resolution of 1 microsecond, so this causes
+# failures on JRuby 1.7.5 to 1.7.9.
+#
+# Determine what the platform supports and adjust the tests accordingly.
+DATETIME_RESOLUTION = (0..5).collect {|i| 10**i}.find {|i| (DateTime.new(2013,1,1,0,0,0) <=> DateTime.new(2013,1,1,0,0,Rational(i,1000000))) < 0}
+raise 'Unable to compare DateTimes at a resolution less than one second on this platform' unless DATETIME_RESOLUTION