Class: Nukumber::Reporter::Colour

Inherits:
Abstract
  • Object
show all
Defined in:
lib/nukumber/reporter/colour.rb

Direct Known Subclasses

Mono

Instance Method Summary collapse

Methods inherited from Abstract

#initialize, #terminate

Constructor Details

This class inherits a constructor from Nukumber::Reporter::Abstract

Instance Method Details

#begin_element(element) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/nukumber/reporter/colour.rb', line 55

def begin_element(element)
  @indent = 1
  puts_cyan "#{element.keyword}: #{element.name}"
  puts_grey "#{element.feature.file_path.split('/').last}:#{element.line}"
  if element.is_a? Nukumber::Model::ScenarioOutline
    element.steps.each { |step| print_step(step, :outline) }
    @indent = 3
    puts_cyan table_row_printable(element.examples.table, nil)
  end
end

#begin_feature(feature) ⇒ Object



50
51
52
53
# File 'lib/nukumber/reporter/colour.rb', line 50

def begin_feature(feature)
  @indent = 0
  puts_cyan "#{feature.keyword}: #{feature.name}"
end

#error(exception, element) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/nukumber/reporter/colour.rb', line 94

def error(exception, element)
  @indent = 2
  puts_red exception.message
  @indent = 3
  filtered_backtrace(exception.backtrace).each { |l| puts_red l }
  puts_red "#{element.feature.file_path}:#{element.line}"
end

#final_report(passed, failed, pending, undefined) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/nukumber/reporter/colour.rb', line 102

def final_report(passed, failed, pending, undefined)
  @indent = 0
  puts_green "\n#{passed.size} test#{passed.size == 1 ? '' : 's'} passed"
  puts_cyan "#{pending.size} test#{pending.size == 1 ? '' : 's'} pending"
  puts_yellow "#{undefined.size} test#{undefined.size == 1 ? '' : 's'} undefined"
  puts_red "#{failed.size} test#{failed.size == 1 ? '' : 's'} failed#{failed.size == 0 ? '' : ':'}"
  @indent = 1
  failed.each { |f| puts_red "#{f.feature.file_path}:#{f.line} # #{f.name}" }
end


90
91
92
# File 'lib/nukumber/reporter/colour.rb', line 90

def print_example(table, row, status = :passed)
  puts_status(table_row_printable(table, row), status)
end


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/nukumber/reporter/colour.rb', line 112

def print_skeleton_code(elements)
  @indent = 0
  puts_empty_line
  puts_yellow "Build Nukumber test definitions something like this:"
  puts_empty_line
  elements.each do |element|
    @indent = 0
    puts_yellow "def #{element.shortsym}"
    @indent = 1
    puts_yellow "# $args is a Hash (or Array of Hashes) representing any step arguments"
    puts_yellow "# $example is a Hash representing the current row for this outline" if element.is_a? Nukumber::Model::ScenarioOutline
    puts_yellow "# Now precede each \"pass\" line below with the code it describes..."
    puts_yellow "pending"
    element.steps.each do |step|
      puts_yellow "pass \"#{step.name.gsub('"', '\"')}\""
    end
    @indent = 0
    puts_yellow "end"
    puts_empty_line
  end
end


79
80
81
82
83
84
85
86
87
88
# File 'lib/nukumber/reporter/colour.rb', line 79

def print_step(step, status = :passed)
  @indent = 2
  puts_status("#{step.keyword}#{step.name}", status)
  @indent = 3
  unless step.args.empty?
    (0..step.args.row_count).each do |i|
      puts_status(table_row_printable(step.args, i - 1), status)
    end
  end
end

#undefined_element(element) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nukumber/reporter/colour.rb', line 66

def undefined_element(element)
  @indent = 1
  puts_yellow "#{element.keyword}: #{element.name}"
  puts_grey "#{element.feature.file_path.split('/').last}:#{element.line}"
  element.steps.each { |step| print_step(step, :undefined) }
  if element.is_a? Nukumber::Model::ScenarioOutline
    @indent = 3
    (0..element.examples.table.row_count).each do |i|
      puts_status(table_row_printable(element.examples.table, i - 1), :undefined)
    end
  end
end