Class: TinyTest::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/tinytest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Runner

Receives args as a keyword-argument-hash.

reporter

reporter, an object to respond to messages like TinyTest::Reporter.

testname

matcher for testing method names. (Default; /Atest/)

testcase

matcher for TestCase’s subclass names. (Default; matchs to any name)

verbose

run on verbose mode or not; set value to attribute #verbose.

matcher means a object which is enable to respond to #===; it receives a test method name or testcase class and returns a the argument matches or not.



36
37
38
39
40
41
42
43
# File 'lib/tinytest.rb', line 36

def initialize(args = {})
  @reporter = args.fetch(:reporter, Reporter.new)
  tn_matcher = args.fetch(:testname, /\Atest/)
  @testname_matcher = normalize_callable_matcher(tn_matcher)
  tc_matcher = args.fetch(:testcase, /./)
  @testcase_matcher = normalize_callable_matcher(tc_matcher){|klass| klass.name }
  self.verbose = args.fetch(:verbose, false)
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



45
46
47
# File 'lib/tinytest.rb', line 45

def verbose
  @verbose
end

Instance Method Details

#runObject

Executes each test.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tinytest.rb', line 48

def run
  @reporter.load_suite($0)
  n_assertions, results, bench = run_suites(collect_suites())
  if self.verbose
    @reporter.mark_results_with_times(results)
  else
    @reporter.mark_results(results)
  end
  @reporter.running_times(bench)
  not_succeededs = results.reject{|r| r.success? }
  if not_succeededs.empty?
    @reporter.blank
  else
    @reporter.error_reports(not_succeededs)
  end
  f, e, s = count_suiteresults_types(results)
  @reporter.counts_report(results.size, n_assertions, f, e, s)
  f + e unless results.empty?
end