Module: Must::Test::Unit

Defined in:
lib/must/test/unit/version.rb,
lib/must.rb

Constant Summary collapse

VERSION =
"0.5.0"

Instance Method Summary collapse

Instance Method Details

#must(name, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/must.rb', line 8

def must(name, &block)
  # convert "any method description" to any_method_description
  test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym

  # don't define a new method if its already defined
  defined = instance_method(test_name) rescue false
  raise "#{test_name} is already defined on #{self}" if defined

  if block_given?
    # define the actual test_something_is_valid TestCase method
    # pass it its functionality through a closure block
    define_method(test_name, &block)
  else
    define_method(test_name) do
      flunk "No implementation provided for #{name}"
    end
  end
end