From 2cd23c61d63fa85ff5b77526bb2e1d9c70e617ce Mon Sep 17 00:00:00 2001 From: Jeremy McAnally Date: Mon, 29 Dec 2008 22:49:14 -0600 Subject: [PATCH] Initial commit --- History.txt | 4 +++ Manifest.txt | 6 ++++ README.txt | 74 ++++++++++++++++++++++++++++++++++++++++++++ Rakefile | 26 ++++++++++++++++ lib/pending.rb | 48 ++++++++++++++++++++++++++++ test/test_pending.rb | 54 ++++++++++++++++++++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 History.txt create mode 100644 Manifest.txt create mode 100644 README.txt create mode 100644 Rakefile create mode 100644 lib/pending.rb create mode 100644 test/test_pending.rb diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..9c32871 --- /dev/null +++ b/History.txt @@ -0,0 +1,4 @@ +== 1.0.0 / 2008-12-29 + +* 1 major enhancement + * Birthday! diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..5bc5bf2 --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,6 @@ +History.txt +Manifest.txt +README.txt +Rakefile +lib/pending.rb +test/test_pending.rb diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..52df141 --- /dev/null +++ b/README.txt @@ -0,0 +1,74 @@ +pending + by Jeremy McAnally + http://jeremymcanally.com + +== DESCRIPTION: + +pending lets you define a block of test code that is currently "pending" functionality, +similar to RSpec's pending method. + +== FEATURES/PROBLEMS: + +* A pending method to let you define pending test code + +== SYNOPSIS: + +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: + + did not fail. + +If the test fails (i.e., the functionality isn't implemented), then it will +not fail the surrounding test. + +== REQUIREMENTS: + +* Test::Unit + +== INSTALL: + + sudo gem install pending + +== LICENSE: + +(The MIT License) + +Copyright (c) 2008 FIXME (different license?) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..fb43ade --- /dev/null +++ b/Rakefile @@ -0,0 +1,26 @@ +# Look in the tasks/setup.rb file for the various options that can be +# configured in this Rakefile. The .rake files in the tasks directory +# are where the options are used. + +begin + require 'bones' + Bones.setup +rescue LoadError + load 'tasks/setup.rb' +end + +ensure_in_path 'lib' +require 'pending' + +task :default => 'spec:run' + +PROJ.name = 'pending' +PROJ.authors = 'FIXME (who is writing this software)' +PROJ.email = 'FIXME (your e-mail)' +PROJ.url = 'FIXME (project homepage)' +PROJ.version = '0.1' +PROJ.rubyforge.name = 'pending' + +PROJ.spec.opts << '--color' + +# EOF diff --git a/lib/pending.rb b/lib/pending.rb new file mode 100644 index 0000000..b526d93 --- /dev/null +++ b/lib/pending.rb @@ -0,0 +1,48 @@ +module Test + module Unit + class TestCase + # 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: + # + # did not fail. + # + # If the test fails (i.e., the functionality isn't implemented), then it will + # not fail the surrounding test. + # + def pending(description = "", &block) + if block_given? + failed = false + + begin + block.call + rescue + failed = true + end + + flunk("<#{description}> did not fail.") unless failed + end + + print "P" + end + end + end +end \ No newline at end of file diff --git a/test/test_pending.rb b/test/test_pending.rb new file mode 100644 index 0000000..4ad9d69 --- /dev/null +++ b/test/test_pending.rb @@ -0,0 +1,54 @@ +require 'test/unit' +require File.dirname(__FILE__) + "/../lib/pending.rb" + +# Quick and dirty way to test our output +class StdoutStub + attr_accessor :text + + def write(text) + @text = text + end +end + +class TestPending < Test::Unit::TestCase + def test_output + old = $stdout + $> = StdoutStub.new + pending("poop") + + assert_equal "P", $>.text + $> = $stdout + end + + def test_does_not_require_block + assert_nothing_raised do + pending("hello there") + end + end + + def test_block_allows_fail + assert_nothing_raised do + pending("this is awesome") do + assert false + end + end + end + + def test_flunk_when_no_flunk + assert_raises(Test::Unit::AssertionFailedError) do + pending("this is fail") do + assert true + end + end + end + + def test_output_of_flunk_when_no_flunk + begin + pending("this is fail") do + assert true + end + rescue StandardError => e + assert_equal " did not fail.", e.message + end + end +end \ No newline at end of file