module TestBench::Bootstrap::Fixture
Public Class Methods
print_error(error)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 111 def self.print_error(error) omit_backtrace_pattern = ENV['TEST_BENCH_OMIT_BACKTRACE_PATTERN'] omit_backtrace_pattern ||= %r{test_bench/bootstrap\.rb} omitting = false Output.write("\e[1mTraceback\e[22m (most recent call last):", sgr_code: 0x31) rjust_length = error.backtrace.length.to_s.length error.backtrace[1..-1].reverse_each.with_index do |line, index| line = line.dup line.chomp! if omit_backtrace_pattern.match?(line) if omitting next else omitting = true header = index.to_s.gsub(/./, '?').rjust(rjust_length, ' ') Output.write("#{header}: *omitted*", sgr_codes: [0x2, 0x3, 0x31], tab_indent: true) end else omitting = false header = index.to_s.rjust(rjust_length, ' ') Output.write("#{header}: #{line}", sgr_code: 0x31, tab_indent: true) end end if error.message.empty? if error.instance_of?(RuntimeError) Output.write("#{error.backtrace[0]}: \e[1;4munhandled exception\e[24;22m", sgr_code: 0x31) return end error.message = error.class end Output.write("#{error.backtrace[0]} \e[1m#{error} (\e[4m#{error.class}\e[24m)\e[22m", sgr_code: 0x31) end
Public Instance Methods
_context(prose=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 71 def _context(prose=nil, &block) context(prose) end
_test(prose=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 95 def _test(prose=nil, &block) test(prose) end
assert(value)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 8 def assert(value) unless value raise AssertionFailure.build(caller.first) end end
assert_raises(error_class=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 14 def assert_raises(error_class=nil, &block) begin block.() rescue (error_class || StandardError) => error return if error_class.nil? if error.instance_of?(error_class) return else raise error end end raise AssertionFailure.build(caller.first) end
comment(text)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 99 def comment(text) Output.write(text) end
context(prose=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 48 def context(prose=nil, &block) if block.nil? Output.write(prose || 'Context', sgr_code: 0x33) return end unless prose.nil? Output.indent(prose, sgr_code: 0x32) do context(&block) end return end begin block.() rescue => error Fixture.print_error(error) raise Failure.build end end
fixture(cls, *args, **kwargs, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 103 def fixture(cls, *args, **kwargs, &block) fixture = TestBench::Fixture.(cls, *args, **kwargs, &block) passed = !fixture.test_session.failed? assert(passed) end
refute(value)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 31 def refute(value) if value raise AssertionFailure.build(caller.first) end end
refute_raises(error_class=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 37 def refute_raises(error_class=nil, &block) block.() rescue (error_class || StandardError) => error unless error.instance_of?(error_class) raise error end raise AssertionFailure.build(caller.first) end
test(prose=nil, &block)
click to toggle source
# File lib/test_bench/bootstrap.rb, line 75 def test(prose=nil, &block) if block.nil? Output.write(prose || 'Test', sgr_code: 0x33) return end begin block.() Output.indent(prose, sgr_code: 0x32) rescue => error Output.indent(prose, sgr_codes: [0x1, 0x31]) do Fixture.print_error(error) end raise Failure.build end end