Class: Sapphire::Testing::ConsoleReporter

Inherits:
Reporter show all
Defined in:
lib/sapphire/Testing/ConsoleReporter.rb

Instance Attribute Summary

Attributes inherited from Reporter

#broken_count, #failing_count, #passing_count, #pending_count, #test_count, #time

Instance Method Summary collapse

Constructor Details

#initializeConsoleReporter

Returns a new instance of ConsoleReporter.



5
6
7
8
9
10
11
12
13
14
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 5

def initialize
  @not_passing = {}
  @passing_count = 0
  @failing_count = 0
  @pending_count = 0
  @broken_count = 0
  @test_count = 0
  $console ||= $stdout
  @output = $console
end

Instance Method Details

#Add(r) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 97

def Add(r)
  result_passes = r.type == "pass"

  if !result_passes and (r.item.is_a? Given or r.item.is_a? Background)
    @not_passing = @not_passing.merge!({ r => r })
  elsif !result_passes and (r.item.is_a? When)
    @not_passing = @not_passing.merge!({ r.parent => r.parent })
  elsif !result_passes and (r.item.is_a? And and r.item.parent.is_a? Given)
    @not_passing = @not_passing.merge!({ r.parent => r.parent })
  elsif !result_passes and (r.item.is_a? And and r.parent.item.is_a? When)
    @not_passing = @not_passing.merge!({ r.parent.parent => r.parent.parent })
  elsif !result_passes and (r.item.is_a? Then)
    @not_passing = @not_passing.merge!({ r.parent.parent => r.parent.parent })
  elsif !result_passes and (r.item.is_a? And and r.parent.item.is_a? Then)
    @not_passing = @not_passing.merge!({ r.parent.parent.parent => r.parent.parent.parent })
  elsif r.item.is_a? TestPlan
    @not_passing = @not_passing.merge!({ r => r })
  end

end

#BeginTestingObject



165
166
167
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 165

def BeginTesting
  @start = Time.now
end

#Indent(depth) ⇒ Object



24
25
26
27
28
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 24

def Indent(depth)
  (1..depth).each do
    @output.print "\t"
  end
end

#InsertLineBreakObject



66
67
68
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 66

def InsertLineBreak()
  @output.puts ""
end

#Output(result, depth) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 135

def Output(result, depth)

  self.PrintItem(result, depth)

  result.results.each do |sub_result|
    self.Output(sub_result, depth+1)
  end
end

#OutputResultsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 118

def OutputResults()
  @output.puts ""


  @not_passing.keys.each do |key|
    self.PrintResult @not_passing[key]
  end

  @output.puts ""
  @output.puts "Finished in " + (@end - @start).round().to_s + " seconds."
  @output.puts "Test Count: " + @test_count.to_s
  @output.puts "Passing: " + @passing_count.to_s
  @output.puts "Failing: " + @failing_count.to_s
  @output.puts "Pending: " + @pending_count.to_s
  @output.puts "Broken: " + @broken_count.to_s
end

#PrintItem(result, depth) ⇒ Object



30
31
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
62
63
64
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 30

def PrintItem(result, depth)
  Indent(depth)

  if result.type == 'pass'
    @output.puts result.text
  elsif result.type == 'pending'
    @output.puts result.text
    Indent(depth+1)
    @output.puts " ## Not Yet Implemented ##"
  elsif result.type == 'broken'
    @output.puts result.text
    Indent(depth+1)
    @output.puts " ## Broken ##"
  else
    @output.puts result.text
    if result.messages.is_a? Array
      result.messages.each do |message|
        Indent(depth+1)
        @output.puts message
      end

    else
      Indent(depth+1)
      @output.puts result.messages
    end
    @output.puts ""
    result.stack.each do |line|
      if (!line.include? "sapphire" and ! line.include? "-e:1:in")
        Indent(depth+1)
        @output.puts line
      end
    end

  end
end

#PrintResult(entry) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 144

def PrintResult(entry)
  if entry.item.is_a? Background
    self.InsertLineBreak
    self.Output entry, 0
    self.InsertLineBreak
  elsif entry.item.is_a? Given
    self.InsertLineBreak
    self.Output entry, 1
    self.InsertLineBreak
  elsif entry.item.is_a? When
    self.PrintItem entry.parent, 0
    self.Output entry, 1
    self.InsertLineBreak
  elsif entry.item.is_a? TestPlan
    self.PrintItem entry, 0
    self.InsertLineBreak
  else
    self.PrintResult entry.parent
  end
end

#ScenarioComplete(scenario) ⇒ Object



20
21
22
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 20

def ScenarioComplete(scenario)
  @output.puts ""
end

#ScenarioStart(scenario) ⇒ Object



16
17
18
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 16

def ScenarioStart(scenario)
  @output.puts scenario.file_name + ": "
end

#TestBroken(test) ⇒ Object



91
92
93
94
95
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 91

def TestBroken(test)
  @broken_count = @broken_count + 1
  Add test
  @output.print "B"
end

#TestFailed(test) ⇒ Object



79
80
81
82
83
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 79

def TestFailed(test)
  @failing_count = @failing_count + 1
  Add test
  @output.print "F"
end

#TestingCompleteObject



169
170
171
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 169

def TestingComplete
  @end = Time.now
end

#TestPassed(test) ⇒ Object



74
75
76
77
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 74

def TestPassed(test)
  @passing_count = @passing_count + 1
  @output.print "."
end

#TestPending(test) ⇒ Object



85
86
87
88
89
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 85

def TestPending(test)
  @pending_count = @pending_count + 1
  Add test
  @output.print "*"
end

#TestStarted(test) ⇒ Object



70
71
72
# File 'lib/sapphire/Testing/ConsoleReporter.rb', line 70

def TestStarted(test)
  @test_count = @test_count + 1
end