class MiniSpec::Reporter
Attributes
failed_specs[R]
failed_tests[R]
skipped_tests[R]
Public Class Methods
new(stdout = STDOUT)
click to toggle source
# File lib/minispec/reporter.rb, line 7 def initialize stdout = STDOUT @stdout = stdout @failed_specs, @failed_tests, @skipped_tests = [], {}, {} end
Public Instance Methods
exception_details(spec, test, exception)
click to toggle source
# File lib/minispec/reporter.rb, line 100 def exception_details spec, test, exception puts(info([spec, test]*' / ')) puts(error(exception.message), indent: 2) exception.backtrace.each {|l| puts(info(MiniSpec::Utils.shorten_source(l)), indent: 2)} puts('---', '') end
failure_details(spec, test, failure)
click to toggle source
# File lib/minispec/reporter.rb, line 107 def failure_details spec, test, failure puts(info([spec, test]*' / ')) puts(error(callerline(failure[:callers][0])), indent: 2) callers(failure[:callers]).each {|l| puts(info(l), indent: 2)} puts return puts(*failure[:message].split("\n"), '', indent: 2) if failure[:message] return if failure[:right_object] == :__ms__right_object expected, actual = [:right_object, :left_object].map do |obj| str = stringify_object(failure[obj]) [str =~ /\n/ ? :puts : :print, str] end send(expected.first, info(' Expected: ')) print('NOT ') if failure[:negation] puts(expected.last) send(actual.first, info(' Actual: ')) puts(actual.last) print(info(' Compared using: ')) puts(failure[:right_method]) diff = diff(actual.last, expected.last) puts(info(' Diff: '), diff) unless diff.empty? puts('---', '') end
failures?()
click to toggle source
# File lib/minispec/reporter.rb, line 161 def failures? @failed_specs.any? || @failed_tests.any? end
mark_as_failed(spec, test, verb, proc, failures)
click to toggle source
# File lib/minispec/reporter.rb, line 144 def mark_as_failed spec, test, verb, proc, failures puts(error("FAILED")) (@failed_tests[spec] ||= []).push([test, verb, proc, failures]) end
mark_as_passed(spec, test)
click to toggle source
# File lib/minispec/reporter.rb, line 135 def mark_as_passed spec, test puts(success("OK")) end
mark_as_skipped(spec, test, source_location)
click to toggle source
# File lib/minispec/reporter.rb, line 139 def mark_as_skipped spec, test, source_location puts(warn("Skipped")) (@skipped_tests[spec] ||= []).push([test, source_location]) end
print(*args)
click to toggle source
# File lib/minispec/reporter.rb, line 149 def print(*args); @stdout.print(*indent_lines(*args)) end
puts(*args)
click to toggle source
# File lib/minispec/reporter.rb, line 150 def puts(*args); @stdout.puts(*indent_lines(*args)) end
summary()
click to toggle source
# File lib/minispec/reporter.rb, line 12 def summary summary__failed_specs summary__failed_tests summary__skipped_tests totals end
summary__failed_specs()
click to toggle source
# File lib/minispec/reporter.rb, line 19 def summary__failed_specs return if @failed_specs.empty? puts puts(error('--- Failed Specs ---')) last_ex = nil @failed_specs.each do |(spec,proc,ex)| puts(info(spec)) puts(info('defined at ' + proc.source_location.join(':')), indent: 2) if proc.is_a?(Proc) if last_ex && ex.backtrace == last_ex.backtrace puts('see exception above', indent: 2) next end last_ex = ex puts(error(ex.message), indent: 2) ex.backtrace.each {|l| puts(l, indent: 2)} puts end end
summary__failed_tests()
click to toggle source
# File lib/minispec/reporter.rb, line 53 def summary__failed_tests return if @failed_tests.empty? puts puts(error('--- Failed Tests ---'), '') @failed_tests.each_pair do |spec, failures| @failed_specs.push(spec) # to be used on #totals__specs failures.each do |(test,verb,proc,errors)| errors.each do |error| error.is_a?(Exception) ? exception_details(spec, test, error) : failure_details(spec, test, error) end end end end
summary__skipped_tests()
click to toggle source
# File lib/minispec/reporter.rb, line 38 def summary__skipped_tests return if @skipped_tests.empty? puts puts(warn('--- Skipped Tests ---')) @skipped_tests.each_pair do |spec,tests| puts(info(spec)) tests.each do |(test,source_location)| puts(warn(test), indent: 2) puts(info(MiniSpec::Utils.shorten_source(source_location)), indent: 2) puts end puts end end
totals()
click to toggle source
# File lib/minispec/reporter.rb, line 69 def totals puts puts('---') totals__specs totals__tests totals__assertions end
totals__assertions()
click to toggle source
# File lib/minispec/reporter.rb, line 93 def totals__assertions print(info(' Assertions: ')) return puts(success(Minispec.assertions)) if @failed_tests.empty? print(info(Minispec.assertions)) puts(error(' (%s failed)' % @failed_tests.values.map(&:size).reduce(:+))) end
totals__specs()
click to toggle source
# File lib/minispec/reporter.rb, line 77 def totals__specs print(info(' Specs: ')) return puts(success(Minispec.specs.size)) if @failed_specs.empty? print(info(Minispec.specs.size)) puts(error(' (%s failed)' % @failed_specs.size)) end
totals__tests()
click to toggle source
# File lib/minispec/reporter.rb, line 84 def totals__tests print(info(' Tests: ')) print(send(@failed_tests.any? ? :info : :success, Minispec.tests)) failed = error(' (%s failed)' % @failed_tests.values.map(&:size).reduce(:+)) if @failed_tests.any? skipped = warn(' (%s skipped)' % @skipped_tests.size) if @skipped_tests.any? report = [failed, skipped].compact.join(', ') puts(report) end
Private Instance Methods
callerline(caller)
click to toggle source
# File lib/minispec/reporter.rb, line 175 def callerline caller file, line = caller.match(/^(.+?):(\d+)(?::in `(.*)')?/) {|m| m[1..2]} return unless lines = MiniSpec.source_location_cache(file) (line = lines[line.to_i - 1]) && line.strip end
callers(*callers)
click to toggle source
# File lib/minispec/reporter.rb, line 171 def callers *callers callers.flatten.uniq.reverse.map {|l| MiniSpec::Utils.shorten_source(l)} end
diff(actual, expected)
click to toggle source
# File lib/minispec/reporter.rb, line 185 def diff actual, expected @differ ||= MiniSpec::Differ.new(color: true) @differ.diff(actual, expected).strip end
indent_lines(*args)
click to toggle source
# File lib/minispec/reporter.rb, line 166 def indent_lines *args opts = args.last.is_a?(Hash) ? args.pop : {} (i = opts[:indent]) && (i = @@indent*i) && args.map {|l| i + l} || args end
stringify_object(obj)
click to toggle source
# File lib/minispec/reporter.rb, line 181 def stringify_object obj obj.is_a?(String) ? obj : MiniSpec::Utils.pp(obj) end