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
-
#display_name ⇒ Object
Partially demodulized class name, used for display purposes.
-
#duration ⇒ Object
Test’s duration.
-
#env ⇒ Object
Environment on which test was run.
-
#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 |
# File 'lib/test/status.rb', line 42 def initialize @results = [] end |
Instance Attribute Details
#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
36 37 38 |
# File 'lib/test/status.rb', line 36 def duration @duration end |
#env ⇒ Object
Environment on which test was run
24 25 26 |
# File 'lib/test/status.rb', line 24 def env @env end |
#log_path ⇒ Object
TODO: Burn it with fire… Path to test’s log, for purpose of making test logs accessible via listeners
40 41 42 |
# File 'lib/test/status.rb', line 40 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
27 28 29 |
# File 'lib/test/status.rb', line 27 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
33 34 35 |
# File 'lib/test/status.rb', line 33 def time_end @time_end end |
#time_start ⇒ Object
Time of test’s start
30 31 32 |
# File 'lib/test/status.rb', line 30 def time_start @time_start end |
Instance Method Details
#finalize_run ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/test/status.rb', line 57 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
46 47 48 49 50 51 52 53 54 |
# File 'lib/test/status.rb', line 46 def initialize_run if @time_start.nil? @time_start = Time.now.to_f end 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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/test/status.rb', line 70 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
89 90 91 92 93 |
# File 'lib/test/status.rb', line 89 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.
98 99 100 101 102 103 104 105 |
# File 'lib/test/status.rb', line 98 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 |