Class: Uspec::Stats

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



3
4
5
# File 'lib/uspec/stats.rb', line 3

def initialize
  clear_results!
end

Instance Attribute Details

#failureObject (readonly)

Returns the value of attribute failure.



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

def failure
  @failure
end

#pendingObject (readonly)

Returns the value of attribute pending.



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

def pending
  @pending
end

#successObject (readonly)

Returns the value of attribute success.



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

def success
  @success
end

Instance Method Details

#<<(result) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/uspec/stats.rb', line 8

def << result
  if result.success?
    self.success << result
  elsif result.pending?
    self.pending << result
  else
    self.failure << result
  end
end

#clear_results!Object



18
19
20
21
22
# File 'lib/uspec/stats.rb', line 18

def clear_results!
  @success = Array.new
  @failure = Array.new
  @pending = Array.new
end

#resultsObject



24
25
26
# File 'lib/uspec/stats.rb', line 24

def results
  @success + @failure + @pending
end

#summaryObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/uspec/stats.rb', line 28

def summary
  [
    "test summary: ",
    Uspec::Terminal.green("#{@success.size} successful"),
    ", ",
    Uspec::Terminal.red("#{@failure.size} failed"),
    ", ",
    Uspec::Terminal.yellow("#{@pending.size} pending")
  ].join
end