Class: Protest::Report

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.on(event, &block) ⇒ Object

Define an event handler for your report. The different events fired in a report’s life cycle are:

:start

Fired by the runner when starting the whole test suite.

:enter

Fired by the runner when starting a particular test case. It will get the test case as an argument.

:test

Fired by a test before it starts running. It will get the instance of TestCase for the given test as an argument.

:assertion

Fired by a test each time an assertion is run.

:pass

Fired by a test after it runs successfully without errors. It will get an instance of PassedTest as an argument.

:pending

Fired by a test which doesn’t provide a test block or which calls TestCase#pending. It will get an instance of PendingTest as an argument.

:failure

Fired by a test in which an assertion failed. It will get an instance of FailedTest as an argument.

:error

Fired by a test where an uncaught exception was found. It will get an instance of ErroredTest as an argument.

:exit

Fired by the runner each time a test case finishes. It will take the test case as an argument.

:end

Fired by the runner at the end of the whole test suite.

The event handler will receive the report as a first argument, plus any arguments documented above (depending on the event). It will also ensure that any handler for the same event declared on an ancestor class is run.

[View source]

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

def self.on(event, &block)
  define_method(:"on_#{event}") do |*args|
    begin
      super(*args)
    rescue NoMethodError
    end

    block.call(self, *args)
  end
end

Instance Method Details

#add_assertionObject

Log an assertion was run (whether it succeeded or failed.)

[View source]

97
98
99
100
# File 'lib/protest/report.rb', line 97

def add_assertion
  @assertions ||= 0
  @assertions += 1
end

#assertionsObject

Number of assertions run during the report.

[View source]

103
104
105
# File 'lib/protest/report.rb', line 103

def assertions
  @assertions || 0
end

#errorsObject

List all the tests (as ErroredTest instances) that raised an unrescued exception.

[View source]

86
87
88
# File 'lib/protest/report.rb', line 86

def errors
  @errors ||= []
end

#failuresObject

List all the tests (as FailedTest instances) that failed an assertion.

[View source]

80
81
82
# File 'lib/protest/report.rb', line 80

def failures
  @failures ||= []
end

#failures_and_errorsObject

Aggregated and ordered list of tests that either failed an assertion or raised an unrescued exception. Useful for displaying back to the user.

[View source]

92
93
94
# File 'lib/protest/report.rb', line 92

def failures_and_errors
  @failures_and_errors ||= []
end

#passesObject

List all the tests (as PassedTest instances) that passed.

[View source]

75
76
77
# File 'lib/protest/report.rb', line 75

def passes
  @passes ||= []
end

#pendingsObject

List all the tests (as PendingTest instances) that were pending.

[View source]

70
71
72
# File 'lib/protest/report.rb', line 70

def pendings
  @pendings ||= []
end

#testsObject

[View source]

107
108
109
# File 'lib/protest/report.rb', line 107

def tests
  @tests ||= []
end

#time_elapsedObject

Seconds taken since the test suite started running

[View source]

117
118
119
# File 'lib/protest/report.rb', line 117

def time_elapsed
  Time.now - @started_at
end

#total_testsObject

Amount ot tests run (whether passed, pending, failed, or errored.)

[View source]

112
113
114
# File 'lib/protest/report.rb', line 112

def total_tests
  tests.size
end