lib/tap/test/subset_test.rb in tap-test-0.4.0 vs lib/tap/test/subset_test.rb in tap-test-0.6.0

- old
+ new

@@ -3,69 +3,55 @@ module Tap module Test # SubsetTest provides methods to conditionally run tests. - # + # # require 'tap/test' # # class Test::Unit::TestCase # # only true if running on windows # condition(:windows) { match_platform?('mswin') } - # + # # # only true if running on anything but windows # condition(:non_windows) { match_platform?('non_mswin') } # end # # Here the WindowsOnlyTest will only run on a Windows platform. Conditions - # like these may be targeted at specific tests when only some tests need + # like these may be targeted at specific tests when only some tests need # to be skipped. - # + # # class RunOnlyAFewTest < Test::Unit::TestCase # include SubsetTest - # + # # def test_runs_all_the_time # assert true # end - # + # # def test_runs_only_if_non_windows_condition_is_true # condition_test(:non_windows) { assert true } # end # end - # + # # def test_runs_only_when_ENV_variable_EXTENDED_is_true # extended_test { assert true } # end - # + # # def test_runs_only_when_ENV_variable_BENCHMARK_is_true # benchmark_test do |x| # x.report("init speed") { 10000.times { Object.new } } # end # end # # def test_runs_only_when_ENV_variable_CUSTOM_is_true # subset_test('CUSTOM') { assert true } # end # end - # + # # In the example, the ENV variables EXTENDED, BENCHMARK, and CUSTOM act as - # flags to run specific tests. If you're running your test using Rake, ENV - # variables can be set from the command line like so: - # - # % EXTENDED=true rake test - # % BENCHMARK=true rake test - # - # Since tap and rap can run rake tasks as well, these are equivalent: - # - # % EXTENDED=true tap run test - # % BENCHMARK=true rap test - # - # To run all tests that get switched using an ENV variable, set ALL=true. - # - # % ALL=true rap test - # - # See SubsetTest::ClassMethods for more information. + # flags to run specific tests. See SubsetTest::ClassMethods for more + # information. module SubsetTest def self.included(base) # :nodoc: super base.extend SubsetTest::ClassMethods @@ -205,40 +191,9 @@ def benchmark_test(length=10, &block) subset_test("BENCHMARK") do puts puts name Benchmark.bm(length, &block) - end - end - - # Declares a subset_test for the ENV variable 'PROMPT'. When run, prompts - # the user for each input specified in array. Inputs will then be passed - # as a hash to the block. Prints 'p' unless run. - # - # def test_requiring_inputs - # prompt_test(:a, :b, :c) {|a, b, c| ... } - # end - # - # If run, the command line prompt will be like the following: - # - # test_requiring_inputs: Enter values or 'skip' - # a: avalue - # b: bvalue - # c: cvalue - # - # The block recieves ['avalue', 'bvalue', 'cvalue']. - def prompt_test(*keys, &block) - subset_test("PROMPT", "p") do - puts "\n#{name} -- Enter values or 'skip'." - - values = keys.collect do |key| - print "#{key}: " - value = gets.strip - flunk "skipped test" if value =~ /skip/i - value - end - - yield(*values) end end end end end \ No newline at end of file