Class: Petitest::Test
- Inherits:
-
Object
- Object
- Petitest::Test
- Defined in:
- lib/petitest/test.rb
Constant Summary collapse
- TEST_METHOD_NAME_PREFIX =
"test_"
Class Attribute Summary collapse
-
.current_description ⇒ Object
Returns the value of attribute current_description.
- .description ⇒ String
- .metadata ⇒ Hash{Symbol => Object}
Class Method Summary collapse
- .children ⇒ Array<Class>
- .description_by_method_name ⇒ Hash{Symbol => String}
- .generate_test_group ⇒ Petitest::TestGroup
- .inherited(child) ⇒ Object
- .method_added(method_name) ⇒ Object
- .test_ancestors ⇒ Array<Class>
- .test_method_names ⇒ Array<Symbol>
- .undefine_test_methods ⇒ Object
Instance Method Summary collapse
- #assert(actual_or_message = nil, message = nil, &block) ⇒ Object
-
#initialize(test_group:, test_method_name:) ⇒ Test
constructor
A new instance of Test.
- #runner ⇒ Petitest::TestRunner
- #skip(message = nil) ⇒ Object
Constructor Details
#initialize(test_group:, test_method_name:) ⇒ Test
Returns a new instance of Test.
92 93 94 95 96 97 98 |
# File 'lib/petitest/test.rb', line 92 def initialize( test_group:, test_method_name: ) @test_group = test_group @test_method_name = test_method_name end |
Class Attribute Details
.current_description ⇒ Object
Returns the value of attribute current_description.
6 7 8 |
# File 'lib/petitest/test.rb', line 6 def current_description @current_description end |
.description ⇒ String
18 19 20 |
# File 'lib/petitest/test.rb', line 18 def description @description ||= name end |
.metadata ⇒ Hash{Symbol => Object}
39 40 41 |
# File 'lib/petitest/test.rb', line 39 def @metadata ||= {} end |
Class Method Details
.children ⇒ Array<Class>
13 14 15 |
# File 'lib/petitest/test.rb', line 13 def children @children ||= [] end |
.description_by_method_name ⇒ Hash{Symbol => String}
23 24 25 |
# File 'lib/petitest/test.rb', line 23 def description_by_method_name @description_by_method_name ||= {} end |
.generate_test_group ⇒ Petitest::TestGroup
28 29 30 |
# File 'lib/petitest/test.rb', line 28 def generate_test_group ::Petitest::TestGroup.new(test_class: self) end |
.inherited(child) ⇒ Object
Note:
Override
33 34 35 36 |
# File 'lib/petitest/test.rb', line 33 def inherited(child) super children << child end |
.method_added(method_name) ⇒ Object
Note:
Override
44 45 46 47 48 49 50 |
# File 'lib/petitest/test.rb', line 44 def method_added(method_name) super if current_description && check_if_test_method_name(method_name) description_by_method_name[method_name] = current_description clear_current_description end end |
.test_ancestors ⇒ Array<Class>
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/petitest/test.rb', line 53 def test_ancestors @test_ancestors ||= ancestors.each_with_object([]) do |klass, classes| if klass == ::Petitest::Test break classes end if klass.is_a?(::Class) classes << klass end end end |
.test_method_names ⇒ Array<Symbol>
65 66 67 68 69 |
# File 'lib/petitest/test.rb', line 65 def test_method_names public_instance_methods.select do |method_name| check_if_test_method_name(method_name) end end |
.undefine_test_methods ⇒ Object
71 72 73 74 75 |
# File 'lib/petitest/test.rb', line 71 def undefine_test_methods test_method_names.each do |method_name| undef_method(method_name) end end |
Instance Method Details
#assert(actual_or_message = nil, message = nil, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/petitest/test.rb', line 102 def assert( = nil, = nil, &block) if block = check( || "Expected given block to return truthy", &block) else actual = check( || "Expected #{actual.inspect} to be truthy") do actual end end end |
#runner ⇒ Petitest::TestRunner
120 121 122 123 124 125 126 |
# File 'lib/petitest/test.rb', line 120 def runner @runner ||= Petitest::TestRunner.new( test: self, test_group: @test_group, test_method_name: @test_method_name, ) end |
#skip(message = nil) ⇒ Object
115 116 117 |
# File 'lib/petitest/test.rb', line 115 def skip( = nil) raise ::Petitest::AssertionSkipError.new() end |