Class: Petitest::TestRunner
- Inherits:
-
Object
- Object
- Petitest::TestRunner
- Defined in:
- lib/petitest/test_runner.rb
Instance Attribute Summary collapse
- #error ⇒ StandardError?
- #finished_at ⇒ Time?
- #started_at ⇒ Time?
- #test ⇒ Petitest::Test readonly
- #test_group ⇒ Petitest::TestGroup readonly
- #test_method_name ⇒ Symbol readonly
Instance Method Summary collapse
- #backtrace ⇒ Array<String>?
- #description ⇒ String
- #error_class_name ⇒ String?
- #error_message ⇒ String?
- #failed? ⇒ Boolean
- #filtered_backtrace ⇒ Array<String>?
- #full_description ⇒ String
-
#initialize(test:, test_group:, test_method_name:) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #inspect ⇒ Object
- #passed? ⇒ Boolean
- #processed? ⇒ Boolean
- #run ⇒ Object
- #skipped? ⇒ Boolean
- #test_method ⇒ Petitest::TestMethod
Constructor Details
#initialize(test:, test_group:, test_method_name:) ⇒ TestRunner
Returns a new instance of TestRunner.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/petitest/test_runner.rb', line 24 def initialize( test:, test_group:, test_method_name: ) @duration = nil @processed = false @test = test @test_group = test_group @test_method_name = test_method_name end |
Instance Attribute Details
#error ⇒ StandardError?
4 5 6 |
# File 'lib/petitest/test_runner.rb', line 4 def error @error end |
#finished_at ⇒ Time?
7 8 9 |
# File 'lib/petitest/test_runner.rb', line 7 def finished_at @finished_at end |
#started_at ⇒ Time?
10 11 12 |
# File 'lib/petitest/test_runner.rb', line 10 def started_at @started_at end |
#test ⇒ Petitest::Test (readonly)
13 14 15 |
# File 'lib/petitest/test_runner.rb', line 13 def test @test end |
#test_group ⇒ Petitest::TestGroup (readonly)
16 17 18 |
# File 'lib/petitest/test_runner.rb', line 16 def test_group @test_group end |
#test_method_name ⇒ Symbol (readonly)
19 20 21 |
# File 'lib/petitest/test_runner.rb', line 19 def test_method_name @test_method_name end |
Instance Method Details
#backtrace ⇒ Array<String>?
37 38 39 40 41 |
# File 'lib/petitest/test_runner.rb', line 37 def backtrace if error error.backtrace end end |
#description ⇒ String
44 45 46 |
# File 'lib/petitest/test_runner.rb', line 44 def description test.class.description_by_method_name[test_method_name] || "##{test_method_name}" end |
#error_class_name ⇒ String?
57 58 59 60 61 |
# File 'lib/petitest/test_runner.rb', line 57 def error_class_name if error error.class.to_s end end |
#error_message ⇒ String?
64 65 66 67 68 |
# File 'lib/petitest/test_runner.rb', line 64 def if error error.to_s end end |
#failed? ⇒ Boolean
71 72 73 |
# File 'lib/petitest/test_runner.rb', line 71 def failed? processed? && !skipped? && !error.nil? end |
#filtered_backtrace ⇒ Array<String>?
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/petitest/test_runner.rb', line 76 def filtered_backtrace @filtered_backtrace ||= begin path = ::File.("../test_group.rb", __FILE__) backtrace.reverse_each.each_with_object([]) do |line, lines| if line.start_with?(path) break lines end unless ::Petitest.configuration.backtrace_filters.any? { |filter| filter === line } lines << line end end.reverse end end |
#full_description ⇒ String
49 50 51 52 53 54 |
# File 'lib/petitest/test_runner.rb', line 49 def full_description [ test_group.full_description, description, ].join(" ") end |
#inspect ⇒ Object
Note:
Override
91 92 93 |
# File 'lib/petitest/test_runner.rb', line 91 def inspect "#<#{self.class}>" end |
#passed? ⇒ Boolean
96 97 98 |
# File 'lib/petitest/test_runner.rb', line 96 def passed? processed? && !skipped? && !failed? end |
#processed? ⇒ Boolean
101 102 103 |
# File 'lib/petitest/test_runner.rb', line 101 def processed? @processed end |
#run ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/petitest/test_runner.rb', line 105 def run self.started_at = ::Time.now test.send(test_method_name) true rescue => error self.error = error false ensure @finished_at = ::Time.now @processed = true end |
#skipped? ⇒ Boolean
118 119 120 |
# File 'lib/petitest/test_runner.rb', line 118 def skipped? processed? && error.is_a?(::Petitest::AssertionSkipError) end |
#test_method ⇒ Petitest::TestMethod
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/petitest/test_runner.rb', line 123 def test_method @test_method ||= begin source_location = test.public_method(test_method_name).source_location ::Petitest::TestMethod.new( line_number: source_location[0], method_name: test_method_name, path: source_location[1], ) end end |