Class: Petitest::TestCase
- Inherits:
-
Object
- Object
- Petitest::TestCase
- Defined in:
- lib/petitest/test_case.rb
Instance Attribute Summary collapse
- #error ⇒ StandardError?
- #finished_at ⇒ Time?
- #started_at ⇒ Time?
- #test_group_class ⇒ Class readonly
- #test_method ⇒ Petitest::TestMethod 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_group_class:, test_method:) ⇒ TestCase
constructor
A new instance of TestCase.
- #passed? ⇒ Boolean
- #processed? ⇒ Boolean
- #run ⇒ Object
- #skipped? ⇒ Boolean
- #test_signature ⇒ String
Constructor Details
#initialize(test_group_class:, test_method:) ⇒ TestCase
Returns a new instance of TestCase.
20 21 22 23 24 25 26 27 28 |
# File 'lib/petitest/test_case.rb', line 20 def initialize( test_group_class:, test_method: ) @duration = nil @processed = false @test_group_class = test_group_class @test_method = test_method end |
Instance Attribute Details
#error ⇒ StandardError?
4 5 6 |
# File 'lib/petitest/test_case.rb', line 4 def error @error end |
#finished_at ⇒ Time?
7 8 9 |
# File 'lib/petitest/test_case.rb', line 7 def finished_at @finished_at end |
#started_at ⇒ Time?
10 11 12 |
# File 'lib/petitest/test_case.rb', line 10 def started_at @started_at end |
#test_group_class ⇒ Class (readonly)
13 14 15 |
# File 'lib/petitest/test_case.rb', line 13 def test_group_class @test_group_class end |
#test_method ⇒ Petitest::TestMethod (readonly)
16 17 18 |
# File 'lib/petitest/test_case.rb', line 16 def test_method @test_method end |
Instance Method Details
#backtrace ⇒ Array<String>?
31 32 33 34 35 |
# File 'lib/petitest/test_case.rb', line 31 def backtrace if error error.backtrace end end |
#description ⇒ String
38 39 40 |
# File 'lib/petitest/test_case.rb', line 38 def description @description ||= "##{method_name}" end |
#error_class_name ⇒ String?
51 52 53 54 55 |
# File 'lib/petitest/test_case.rb', line 51 def error_class_name if error error.class.to_s end end |
#error_message ⇒ String?
58 59 60 61 62 |
# File 'lib/petitest/test_case.rb', line 58 def if error error.to_s end end |
#failed? ⇒ Boolean
65 66 67 |
# File 'lib/petitest/test_case.rb', line 65 def failed? processed? && !error.nil? end |
#filtered_backtrace ⇒ Array<String>?
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/petitest/test_case.rb', line 70 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
43 44 45 46 47 48 |
# File 'lib/petitest/test_case.rb', line 43 def full_description [ test_group_class.full_description, description, ].join(" ") end |
#passed? ⇒ Boolean
85 86 87 |
# File 'lib/petitest/test_case.rb', line 85 def passed? processed? && error.nil? end |
#processed? ⇒ Boolean
90 91 92 |
# File 'lib/petitest/test_case.rb', line 90 def processed? @processed end |
#run ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/petitest/test_case.rb', line 94 def run self.started_at = ::Time.now test_group_class.new.send(test_method.method_name) true rescue => error self.error = error false ensure @finished_at = ::Time.now @processed = true end |
#skipped? ⇒ Boolean
TODO:
108 109 110 |
# File 'lib/petitest/test_case.rb', line 108 def skipped? false end |
#test_signature ⇒ String
113 114 115 |
# File 'lib/petitest/test_case.rb', line 113 def test_signature [test_group_class, test_method.method_name].join("#") end |