Class: Monolens::Command::Tester

Inherits:
Object
  • Object
show all
Includes:
Minitest::Assertions
Defined in:
lib/monolens/command/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Tester

Returns a new instance of Tester.



8
9
10
11
12
13
14
15
# File 'lib/monolens/command/tester.rb', line 8

def initialize(command)
  @command = command
  @nb_tests = 0
  @nb_successes = 0
  @nb_errors = 0
  @nb_failures = 0
  Paint.mode = command.use_paint? ? Paint.detect_mode : 0
end

Instance Attribute Details

#nb_errorsObject

Returns the value of attribute nb_errors.



16
17
18
# File 'lib/monolens/command/tester.rb', line 16

def nb_errors
  @nb_errors
end

#nb_failuresObject

Returns the value of attribute nb_failures.



16
17
18
# File 'lib/monolens/command/tester.rb', line 16

def nb_failures
  @nb_failures
end

#nb_successesObject

Returns the value of attribute nb_successes.



16
17
18
# File 'lib/monolens/command/tester.rb', line 16

def nb_successes
  @nb_successes
end

#nb_testsObject

Returns the value of attribute nb_tests.



16
17
18
# File 'lib/monolens/command/tester.rb', line 16

def nb_tests
  @nb_tests
end

Instance Method Details

#call(lens) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/monolens/command/tester.rb', line 18

def call(lens)
  fail!("No tests found (#{lens.class})") unless lens.is_a?(Monolens::File)

  self.nb_tests = lens.examples.size
  details = []
  lens.examples.each_with_index do |example, i|
    test_one(lens, example, i, details)
  end

  stdout.puts("\n")
  stdout.puts("\n") unless details.empty?
  details.each do |message|
    stdout.puts(message)
  end

  success = nb_errors == 0 && nb_failures == 0
  stdout.puts(success ? green(last_sentence) : red(last_sentence))

  do_exit(1) unless success
end