Method: Test::Unit::TestCase.test
- Defined in:
- lib/test/unit/testcase.rb
.test(*test_description_or_targets, &block) ⇒ Object
Defines a test in declarative syntax or marks following method as a test method.
In declarative syntax usage, the following two test definitions are the almost same:
description "register user"
def test_register_user
...
end
test "register user" do
...
end
In test method mark usage, the “my_test_method” is treated as a test method:
test
def my_test_method
assert_equal("call me", ...)
end
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/test/unit/testcase.rb', line 249 def test(*test_description_or_targets, &block) if block_given? test_description = test_description_or_targets.first if test_description.nil? raise ArgumentError, "test description is missing" end n_arguments = test_description_or_targets.size if n_arguments > 1 = "wrong number of arguments (#{n_arguments} for 1)" raise ArgumentError, end method_name = "test: #{test_description}" define_method(method_name, &block) description(test_description, method_name) attribute(:test, true, {}, method_name) else targets = test_description_or_targets attribute(:test, true, {}, *targets) end end |