lib/petitest/test_group.rb in petitest-0.1.3 vs lib/petitest/test_group.rb in petitest-0.2.0
- old
+ new
@@ -1,9 +1,7 @@
module Petitest
class TestGroup
- include ::Petitest::Assertions
-
TEST_METHOD_NAME_PREFIX = "test_"
class << self
# @return [Array<Class>]
def descendants
@@ -14,11 +12,11 @@
def inherited(sub_class)
super
descendants << sub_class
end
- # @return [Array<Petit::TestCase]
+ # @return [Array<Petit::TestCase>]
def test_cases
descendants.flat_map do |test_group_class|
test_group_class.test_methods.map do |test_method|
::Petitest::TestCase.new(
test_group_class: test_group_class,
@@ -43,9 +41,32 @@
line_number: unbound_method.source_location[1],
method_name: method_name.to_s,
path: unbound_method.source_location[0],
)
end
+ end
+ end
+
+ # @param actual_or_message [Object]
+ # @param message [String, nil]
+ def assert(actual_or_message = nil, message = nil, &block)
+ if block
+ message = actual_or_message
+ check(message || "Given block returned falsy", &block)
+ else
+ actual = actual_or_message
+ check(message || "#{actual.inspect} is not truthy") do
+ actual
+ end
+ end
+ end
+
+ private
+
+ # @param message [String, nil]
+ def check(message, &block)
+ unless block.call
+ raise ::Petitest::AssertionFailureError.new(message)
end
end
end
end