1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
begin
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter '/test/'
add_filter '/vendor/'
end
end
require 'bundler'
Bundler.require
rescue LoadError, Bundler::GemNotFound
end
require 'test/unit'
require 'power_assert'
require 'ripper'
begin
require_relative 'test_core_ext_helper'
rescue LoadError
end
module PowerAssertTestHelper
class << self
def included(base)
base.extend(ClassMethods)
end
end
module ClassMethods
def t(msg='', &blk)
loc = caller_locations(1, 1)[0]
test("#{loc.path} --location #{loc.lineno} #{msg}", &blk)
end
end
private
def _test_parser((expected_idents, expected_paths, source))
parser = ::PowerAssert.const_get(:Parser).new(source, '', 1, -> { var = nil; -> { var } }.().binding, 'assertion_message')
idents = parser.idents
assert_equal expected_idents, map_recursive(idents, &:to_a), source
if expected_paths
assert_equal expected_paths, map_recursive(parser.call_paths, &:name), source
end
end
def map_recursive(ary, &blk)
ary.map {|i| Array === i ? map_recursive(i, &blk) : yield(i) }
end
def assertion_message(source = nil, source_binding = TOPLEVEL_BINDING, &blk)
::PowerAssert.start(source || blk, assertion_method: __callee__, source_binding: source_binding) do |pa|
pa.yield
pa.message
end
end
def strip_color(str)
str.gsub(/(\001)?\e\[.*?(\d)+m(\002)?/, '')
end
end
RubyVM::InstructionSequence.compile_option = {
specialized_instruction: true
}
|