Class: Matest::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



8
9
10
11
# File 'lib/matest.rb', line 8

def initialize
  @example_groups = []
  @info = {}
end

Instance Attribute Details

#example_groupsObject (readonly)

Returns the value of attribute example_groups.



5
6
7
# File 'lib/matest.rb', line 5

def example_groups
  @example_groups
end

#infoObject (readonly)

Returns the value of attribute info.



6
7
8
# File 'lib/matest.rb', line 6

def info
  @info
end

Class Method Details

.runnerObject



13
14
15
# File 'lib/matest.rb', line 13

def self.runner
  @runner ||= new
end

Instance Method Details

#<<(example_group) ⇒ Object



17
18
19
# File 'lib/matest.rb', line 17

def <<(example_group)
  example_groups << example_group
end

#execute!Object



25
26
27
28
29
30
# File 'lib/matest.rb', line 25

def execute!
  example_groups.each do |current_group|
    current_group.execute!
  end
  print_messages
end

#load_file(file) ⇒ Object



21
22
23
# File 'lib/matest.rb', line 21

def load_file(file)
  load(file)
end


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
# File 'lib/matest.rb', line 32

def print_messages
  puts "\n\n### Messages ###"

  statuses = []
  info[:num_specs] = { total: 0 }
  example_groups.each do |current_group|
    current_group.statuses.each do |status|
      info[:num_specs][:total] += 1

      info[:num_specs][status.name] ||= 0
      info[:num_specs][status.name] += 1

      if status.is_a?(Matest::SpecPassed)
      else
        puts "\n[#{status.name}] #{status.description}"
        if status.is_a?(Matest::NotANaturalAssertion)
          puts "  # => #{status.result.inspect}"
        end
        if status.is_a?(Matest::ExceptionRaised)
          puts "EXCEPTION >> #{status.result}"
          status.result.backtrace.each do |l|
            puts "  #{l}"
          end

        end
        puts "  #{status.location}:"
      end
    end
  end
end