test/helper.rb in nanoc-3.7.4 vs test/helper.rb in nanoc-3.7.5
- old
+ new
@@ -28,11 +28,10 @@
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
c.hook_into :webmock
end
module Nanoc::TestHelpers
-
LIB_DIR = File.expand_path(File.dirname(__FILE__) + '/../lib')
def disable_nokogiri?
ENV.key?('DISABLE_NOKOGIRI')
end
@@ -56,11 +55,11 @@
end
def if_implemented
yield
rescue NotImplementedError, NameError
- skip $!
+ skip $ERROR_INFO
return
end
def with_site(params = {})
# Build site name
@@ -157,20 +156,20 @@
$stdout = @orig_stdout
$stderr = @orig_stderr
end
end
- def capturing_stdio(&block)
+ def capturing_stdio(&_block)
# Store
orig_stdout = $stdout
orig_stderr = $stderr
# Run
$stdout = StringIO.new
$stderr = StringIO.new
yield
- { :stdout => $stdout.string, :stderr => $stderr.string }
+ { stdout: $stdout.string, stderr: $stderr.string }
ensure
# Restore
$stdout = orig_stdout
$stderr = orig_stderr
end
@@ -190,11 +189,11 @@
pieces.last.last << line.last
else
pieces << line
end
end
- lines = pieces.map { |p| p.last }
+ lines = pieces.map(&:last)
# Test
b = binding
lines.each_slice(2) do |pair|
actual_out = eval(pair.first, b)
@@ -206,39 +205,39 @@
end
end
def assert_contains_exactly(expected, actual)
assert_equal expected.size, actual.size,
- 'Expected %s to be of same size as %s' % [actual.inspect, expected.inspect]
+ format('Expected %s to be of same size as %s', actual.inspect, expected.inspect)
remaining = actual.dup.to_a
expected.each do |e|
index = remaining.index(e)
remaining.delete_at(index) if index
end
assert remaining.empty?,
- 'Expected %s to contain all the elements of %s' % [actual.inspect, expected.inspect]
+ format('Expected %s to contain all the elements of %s', actual.inspect, expected.inspect)
end
def assert_raises_frozen_error
error = assert_raises(RuntimeError, TypeError) { yield }
assert_match(/(^can't modify frozen |^unable to modify frozen object$)/, error.message)
end
- def with_env_vars(hash, &block)
+ def with_env_vars(hash, &_block)
orig_env_hash = ENV.to_hash
- hash.each_pair { |k,v| ENV[k] = v }
+ hash.each_pair { |k, v| ENV[k] = v }
yield
ensure
- orig_env_hash.each_pair { |k,v| ENV[k] = v }
+ orig_env_hash.each_pair { |k, v| ENV[k] = v }
end
def on_windows?
Nanoc.on_windows?
end
def command?(cmd)
- which, null = on_windows? ? ['where', 'NUL'] : ['which', '/dev/null']
+ which, null = on_windows? ? %w(where NUL) : ['which', '/dev/null']
system("#{which} #{cmd} > #{null} 2>&1")
end
def symlinks_supported?
File.symlink nil, nil
@@ -253,24 +252,21 @@
end
def skip_unless_symlinks_supported
skip 'Symlinks are not supported by Ruby on Windows' unless symlinks_supported?
end
-
end
class Nanoc::TestCase < MiniTest::Unit::TestCase
-
include Nanoc::TestHelpers
-
end
# Unexpected system exit is unexpected
::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.delete(SystemExit)
# A more precise inspect method for Time improves assert failure messages.
#
class Time
def inspect
- strftime("%a %b %d %H:%M:%S.#{'%06d' % usec} %Z %Y")
+ strftime("%a %b %d %H:%M:%S.#{format('%06d', usec)} %Z %Y")
end
end