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
# File lib/pending.rb, line 76 76: def self.pending(description, &block) 77: test_name = "test_#{description.gsub(/\s+/,'_')}".to_sym 78: defined = instance_method(test_name) rescue false 79: raise "#{test_name} is already defined in #{self}" if defined 80: define_method(test_name) do 81: pending(description) {self.instance_eval(&block)} 82: end 83: end
The pending method lets you define a block of test code that is currently “pending” functionality.
You can use it two ways. One is simply put a string as the parameter:
def test_web_service_integration pending "This is not done yet..." end
This will output a “P” in the test output alerting there is pending functionality.
You can also supply a block of code:
def test_new_helpers pending "New helpers for database display" do output = render_record(User.first) assert_equal "Jerry User (jerry@users.com)", output end end
If the block doesn’t fail, then the test will flunk with output like:
<New helpers for database display> did not fail.
If the test fails (i.e., the functionality isn’t implemented), then it will not fail the surrounding test.
# File lib/pending.rb, line 34 34: def pending(description = "", &block) 35: if block_given? 36: failed = false 37: 38: begin 39: block.call 40: rescue 41: failed = true 42: end 43: 44: flunk("<#{description}> did not fail.") unless failed 45: end 46: 47: caller[0] =~ (/(.*):(.*):in `(.*)'/) 48: @@pending_cases << "#{$3} at #{$1}, line #{$2}" 49: print "P" 50: 51: @@at_exit ||= begin 52: at_exit do 53: puts "\nPending Cases:" 54: @@pending_cases.each do |test_case| 55: puts test_case 56: end 57: end 58: end 59: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.