Class: Xcode::Test::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/test/report.rb,
lib/xcode/test/report/test_result.rb,
lib/xcode/test/report/suite_result.rb

Overview

The report is the abstract representation of a collection of suites of tests. Formatters can be attached to write output in real time

Defined Under Namespace

Classes: InvalidStateException, SuiteResult, TestResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Report

Returns a new instance of Report.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xcode/test/report.rb', line 20

def initialize
  @debug = false
  @exit_code = 0
  @suites = []
  @formatters = []
  @start_time = nil
  @end_time = nil
  @unexpected = false
  @observers = []

  yield self if block_given?
end

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



15
16
17
# File 'lib/xcode/test/report.rb', line 15

def end_time
  @end_time
end

#exit_codeObject

Returns the value of attribute exit_code.



15
16
17
# File 'lib/xcode/test/report.rb', line 15

def exit_code
  @exit_code
end

#observersObject (readonly)

Returns the value of attribute observers.



14
15
16
# File 'lib/xcode/test/report.rb', line 14

def observers
  @observers
end

#start_timeObject

Returns the value of attribute start_time.



15
16
17
# File 'lib/xcode/test/report.rb', line 15

def start_time
  @start_time
end

#suitesObject (readonly)

Returns the value of attribute suites.



14
15
16
# File 'lib/xcode/test/report.rb', line 14

def suites
  @suites
end

#unexpectedObject

Returns the value of attribute unexpected.



15
16
17
# File 'lib/xcode/test/report.rb', line 15

def unexpected
  @unexpected
end

Instance Method Details

#abortObject



108
109
110
111
# File 'lib/xcode/test/report.rb', line 108

def abort
  @report.unexpected=true
  finish
end

#add_formatter(format, *args) ⇒ Object



33
34
35
36
37
# File 'lib/xcode/test/report.rb', line 33

def add_formatter(format, *args)
  require "xcode/test/formatters/#{format.to_s}_formatter"
  formatter = Xcode::Test::Formatters.const_get("#{format.to_s.capitalize}Formatter").new(*args)
  @observers << formatter
end

#add_suite(name, time = Time.now) ⇒ Object



64
65
66
67
# File 'lib/xcode/test/report.rb', line 64

def add_suite(name, time=Time.now)
  suite = Xcode::Test::Report::SuiteResult.new(self, name, time)
  @suites << suite
end

#durationObject



73
74
75
76
77
# File 'lib/xcode/test/report.rb', line 73

def duration
  return 0 if @start_time.nil?
  return Time.now - @start_time if @end_time.nil?
  @end_time - @start_time
end

#failed?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xcode/test/report.rb', line 47

def failed?
  return true if unexpected?
  
  @suites.each do |suite|
    suite.tests.each do |test|
      return true if test.failed?
    end
  end

  false
end

#finishObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/xcode/test/report.rb', line 93

def finish
  return if finished?

  # if there is a current suite which isnt finished - finish it
  in_current_suite do |suite|
    unless suite.finished? 
      @unexpected = true
      suite.finish
    end
  end
  
  @end_time = Time.now
  notify_observers :after, self
end

#finished?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/xcode/test/report.rb', line 69

def finished?
  !@end_time.nil?
end

#in_current_suite {|@suites.last| ... } ⇒ Object

Yields:



79
80
81
82
83
# File 'lib/xcode/test/report.rb', line 79

def in_current_suite
  # raise InvalidStateException.new("There is no active suite")
  return if @suites.size==0 or !@suites.last.end_time.nil?
  yield @suites.last
end

#in_current_testObject



85
86
87
88
89
90
91
# File 'lib/xcode/test/report.rb', line 85

def in_current_test
  in_current_suite do |suite|
    # raise InvalidStateException.new("There is no active test case")
    return if suite.tests.size==0
    yield suite.tests.last
  end
end

#notify_observers(event, obj = nil) ⇒ Object



113
114
115
116
117
# File 'lib/xcode/test/report.rb', line 113

def notify_observers(event, obj=nil)
  @observers.each do |f|
    f.send event, obj if f.respond_to? event
  end
end

#startObject



59
60
61
62
# File 'lib/xcode/test/report.rb', line 59

def start
  @start_time = Time.now
  notify_observers :before, self
end

#succeed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/xcode/test/report.rb', line 43

def succeed?
  !self.failed?
end

#unexpected?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/xcode/test/report.rb', line 39

def unexpected?
  @unexpected
end