Skip to content

Commit

Permalink
pending class method that will also define the test
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy McAnally <jeremymcanally@gmail.com>
  • Loading branch information
jduff authored and jm committed Jan 20, 2009
1 parent a229861 commit 3e4524f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/pending.rb
Expand Up @@ -43,6 +43,28 @@ def pending(description = "", &block)

print "P"
end

# This method will define a test method using the description as the test name
# ("pending function" => "test_pending_function")
#
# Instead of doing this:
#
# def test_function_is_pending
# pending "this test is pending"
# end
#
# You can just do this:
#
# pending "function is pending"
#
# This method can be called with a block passed, the same as the instance method
#
def self.pending(description = "", &block)
test_name = "test_#{description.gsub(/\s+/,'_')}".to_sym
defined = instance_method(test_name) rescue false
raise "#{test_name} is already defined in #{self}" if defined
define_method(test_name) { pending(description, &block) }
end
end
end
end
12 changes: 12 additions & 0 deletions test/test_pending.rb
Expand Up @@ -51,4 +51,16 @@ def test_output_of_flunk_when_no_flunk
assert_equal "<this is fail> did not fail.", e.message
end
end

def test_creates_test_method_when_called_on_self
TestPending.pending("this test is pending") do
assert true
end

assert TestPending.instance_methods.include?('test_this_test_is_pending')
assert_raises(Test::Unit::AssertionFailedError) do
send(:test_this_test_is_pending)
end
end

end

0 comments on commit 3e4524f

Please sign in to comment.