Class: Moto::Test::Status
- Inherits:
-
Object
- Object
- Moto::Test::Status
- Defined in:
- lib/test/status.rb
Overview
Representation of single test’s run status - it’s passes, failures etc. Pretty much a value object which’s purpose is to be passed as a data provider for listeners. Only methods here are just meant for data preparation. No communication with any external classes.
Instance Attribute Summary collapse
-
#attempts ⇒ Object
Amount of attempts that have been made to successfuly complete a test.
-
#display_name ⇒ Object
Partially demodulized class name, used for display purposes.
-
#duration ⇒ Object
Test’s duration.
-
#log_path ⇒ Object
TODO: Burn it with fire…
-
#name ⇒ Object
Name of the test.
-
#params ⇒ Object
Set of params on which test was based.
-
#results ⇒ Object
readonly
Array of [Moto::Test::Result], each item represents a result of a single attempt to pass the test.
-
#test_class_name ⇒ Object
Name of the class representing test.
-
#time_end ⇒ Object
Time of test’s finish.
-
#time_start ⇒ Object
Time of test’s start.
Instance Method Summary collapse
- #finalize_run ⇒ Object
-
#initialize ⇒ Status
constructor
A new instance of Status.
- #initialize_run ⇒ Object
-
#log_exception(exception) ⇒ Object
Evaluates result.code and message based on exceptions, dispatched by test during test attempt.
-
#log_failure(message) ⇒ Object
Logs a failure, from assertion or forced, to the list of failures.
-
#to_s ⇒ String
Overwritten definition of to string.
Constructor Details
#initialize ⇒ Status
Returns a new instance of Status.
42 43 44 45 |
# File 'lib/test/status.rb', line 42 def initialize @results = [] @attempts = 0 end |
Instance Attribute Details
#attempts ⇒ Object
Amount of attempts that have been made to successfuly complete a test
40 41 42 |
# File 'lib/test/status.rb', line 40 def attempts @attempts end |
#display_name ⇒ Object
Partially demodulized class name, used for display purposes
18 19 20 |
# File 'lib/test/status.rb', line 18 def display_name @display_name end |
#duration ⇒ Object
Test’s duration
33 34 35 |
# File 'lib/test/status.rb', line 33 def duration @duration end |
#log_path ⇒ Object
TODO: Burn it with fire… Path to test’s log, for purpose of making test logs accessible via listeners
37 38 39 |
# File 'lib/test/status.rb', line 37 def log_path @log_path end |
#name ⇒ Object
Name of the test
12 13 14 |
# File 'lib/test/status.rb', line 12 def name @name end |
#params ⇒ Object
Set of params on which test was based
24 25 26 |
# File 'lib/test/status.rb', line 24 def params @params end |
#results ⇒ Object (readonly)
Array of [Moto::Test::Result], each item represents a result of a single attempt to pass the test
21 22 23 |
# File 'lib/test/status.rb', line 21 def results @results end |
#test_class_name ⇒ Object
Name of the class representing test
15 16 17 |
# File 'lib/test/status.rb', line 15 def test_class_name @test_class_name end |
#time_end ⇒ Object
Time of test’s finish
30 31 32 |
# File 'lib/test/status.rb', line 30 def time_end @time_end end |
#time_start ⇒ Object
Time of test’s start
27 28 29 |
# File 'lib/test/status.rb', line 27 def time_start @time_start end |
Instance Method Details
#finalize_run ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/test/status.rb', line 60 def finalize_run last_result = @results.last if last_result.code == Moto::Test::Result::RUNNING last_result.code = Moto::Test::Result::PASSED end @time_end = Time.now.to_f @duration = time_end - time_start end |
#initialize_run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/test/status.rb', line 47 def initialize_run if @time_start.nil? @time_start = Time.now.to_f end @attempts += 1 result = Moto::Test::Result.new result.code = Moto::Test::Result::RUNNING @results.push(result) end |
#log_exception(exception) ⇒ Object
Evaluates result.code and message based on exceptions, dispatched by test during test attempt
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/test/status.rb', line 73 def log_exception(exception) current_result = @results.last if exception.nil? || exception.is_a?(Moto::Exceptions::TestForcedPassed) current_result.code = Moto::Test::Result::PASSED current_result. = exception. elsif exception.is_a?(Moto::Exceptions::TestSkipped) current_result.code = Moto::Test::Result::SKIPPED current_result. = exception. elsif exception.is_a?(Moto::Exceptions::TestForcedFailure) log_failure(exception.) else current_result.code = Moto::Test::Result::ERROR current_result. = exception. end end |
#log_failure(message) ⇒ Object
Logs a failure, from assertion or forced, to the list of failures
92 93 94 95 96 |
# File 'lib/test/status.rb', line 92 def log_failure() current_result = @results.last current_result.code = Moto::Test::Result::FAILURE current_result.failures.push() end |
#to_s ⇒ String
Overwritten definition of to string.
101 102 103 104 105 106 107 108 |
# File 'lib/test/status.rb', line 101 def to_s case @results.last.code when Moto::Test::Result::PASSED then return 'PASSED' when Moto::Test::Result::FAILURE then return 'FAILED' when Moto::Test::Result::ERROR then return 'ERROR' when Moto::Test::Result::SKIPPED then return 'SKIPPED' end end |