Created
May 5, 2010 21:22
-
-
Save alainravet/391451 to your computer and use it in GitHub Desktop.
add pending tests to TestCAse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
module ActiveSupport | |
class TestCase < Test::Unit::TestCase | |
# Correct Usage : | |
# def test_ok_pending_1 | |
# pending "feature 1 should do this ..." | |
# end | |
# | |
# def test_ok_pending_2 | |
# pending "feature 2 should do this ..." do | |
# assert false | |
# end | |
# end | |
# | |
# Incorrect Usage : | |
# def test_fail_pending_3 | |
# pending "feature 3 should do this ..." do | |
# # a failing test should be here, not error raising code | |
# raise ArgumentError.new "6666666666666666" | |
# end | |
# end | |
# | |
# def test_fail_pending_4 | |
# pending "feature 4 should do this ..." do | |
# # a failing test should be here | |
# end | |
# end | |
def pending(message) | |
raise ArgumentError.new("'pending(); ' requires a message") unless message | |
if block_given? | |
begin | |
yield | |
rescue Test::Unit::AssertionFailedError => e | |
@rescued = true | |
rescue => e | |
@other_error = e | |
@other_error_raised = true | |
ensure | |
if @rescued | |
elsif @other_error_raised | |
flunk "\n \nPending Error (pending block MUST fail, NOT raise a #{@other_error.inspect}!)\n------- \n#{message}" | |
else | |
flunk "\n \nPending Error (pending block MUST fail!)\n------- \n#{message}" | |
end | |
end | |
end | |
puts "\n \nPending\n------- \n#{message}\n" | |
end | |
# Correct usage : | |
# def test_ok_bug_1 | |
# bug "this is bug#1" do | |
# 1/0 # faulty code that raises an error | |
# end | |
# end | |
# | |
# def test_ok_bug_2 | |
# bug "this is bug#2" do | |
# assert_equal 'actual', 'expected' # faulty code test that fails | |
# end | |
# end | |
# | |
# Incorrect usage : | |
# def test_fail_ok_3 | |
# bug "this is bug#3" do | |
# # a failing test or code that raises an error should be here | |
# end | |
# end | |
# | |
def bug(message) | |
raise ArgumentError.new("'bug(); ' requires a message") unless message | |
if block_given? | |
begin | |
yield | |
rescue => e | |
@rescued = true | |
ensure | |
unless @rescued | |
flunk "\n \nBug Error (bug block MUST fail or raise an error!)\n------- \n#{message}" | |
end | |
end | |
end | |
puts "\n \nPending\n------- \n#{message}\n" | |
end | |
private | |
def print_pending_message(message) | |
end | |
end | |
end | |
class BugTest < ActiveSupport::TestCase | |
def test_ok_bug_1 | |
bug "you must fix bug#1" do | |
1/0 | |
end | |
end | |
def test_ok_bug_2 | |
bug "you must fix bug#2" do | |
assert_equal 'actual', 'expected' | |
end | |
end | |
def test_fail_ok_3 | |
bug "you must fix bug#3" do | |
# a failing test or code that raises an error should be here | |
end | |
end | |
end | |
class PendingTest < ActiveSupport::TestCase | |
def test_ok_pending_1 | |
pending "you must implement feature 1" | |
end | |
def test_ok_pending_2 | |
pending "you must implement feature 2" do | |
assert false | |
end | |
end | |
def test_fail_pending_3 | |
pending "you must implement feature 3" do | |
# a failing test should be here, not error raising code | |
raise ArgumentError.new "6666666666666666" | |
end | |
end | |
def test_fail_pending_4 | |
pending "you must implement feature 4" do | |
# a failing test should be here | |
end | |
end | |
end | |
__END__ | |
/usr/bin/ruby -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) /Applications/RubyMine-96.172.app/rb/testing/runner/tunit_class_runner.rb | |
Testing started at 10:30 PM ... | |
Pending Error (pending block MUST raise an AssertionFailedError, and nothing else!) | |
------- | |
you must implement feature 3. | |
test/unit/tk2_test.rb:17:in `pending' | |
test/unit/tk2_test.rb:46:in `test_fail_pending_3' | |
/Users/ara/.gem/ruby/1.8/gems/test-unit-1.2.3/lib/test/unit/ui/testrunnermediator.rb:46:in `old_run_suite' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/testrunnermediator.rb:36:in `run_suite' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:108:in `start_mediator' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:96:in `start' | |
Pending Error (pending block MUST contain a failing test!) | |
------- | |
you must implement feature 4. | |
test/unit/tk2_test.rb:19:in `pending' | |
test/unit/tk2_test.rb:53:in `test_fail_pending_4' | |
/Users/ara/.gem/ruby/1.8/gems/test-unit-1.2.3/lib/test/unit/ui/testrunnermediator.rb:46:in `old_run_suite' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/testrunnermediator.rb:36:in `run_suite' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:108:in `start_mediator' | |
/Applications/RubyMine-96.172.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:96:in `start' | |
Pending | |
------- | |
you must implement feature 1 | |
Pending | |
------- | |
you must implement feature 2 | |
4 tests, 4 assertions, 2 failures, 0 errors | |
Test suite finished: 0.557518 seconds | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment