On Fri, Feb 16, 2007 at 04:25:13AM +0900, Daniel Berger wrote:
> Hi all,
> 
> What's the general approach folks use for skipping tests? Sometimes I
> have some tests that I want to skip based on platform (usually MS
> Windows). I saw the 'flunk' method, but that's considered a failed
> test. I'm looking for something that doesn't treat it as success or
> failure.
> 
> I guess I'd like something like this:
> 
> class TC_Foo < Test::Unit::TestCase
>    def test_bar
>       if RUBY_PLATFORM.match('mswin')
>           skip('There's no Foo::Bar on MS Windows - skipped')
>       else
>           assert_equal(42, Foo::Bar)
>       end
>    end
> end
> 
> And then output that looked like this:
> 
> 1 tests, 0 assertions, 0 failures, 0 errors, 1 skipped
> 
> If there isn't anything like this currently, would patches to add this
> be accepted? I'd be happy to work on it.

Well this may not be the best way but it works.  Although it doesn't
record what methods were skipped.

    % cat platform-filter-test.rb 
    require 'test/unit'

    class MyTest < Test::Unit::TestCase

        def test_adams
           assert(42,"Life, Universe and Everything") 
        end

        def test_baz
            assert(true,"Baz is good")
        end

        def test_skip_mswin
            assert(RUBY_PLATFORM.match('mswin').nil?, "How could I fail.  I should have been skipped. I'm on Windows!!!")
        end

        def test_skip_darwin
            assert(RUBY_PLATFORM.match('darwin').nil?, "How could I fail.  I should have been skipped. I'm on MacOSX!!!")
        end
    end

    % ruby platform-filter-test.rb 
    Loaded suite platform-filter-test
    Started
    ..F.
    Finished in 0.00652 seconds.

      1) Failure:
    test_skip_darwin(MyTest) [platform-filter-test.rb:18]:
    How could I fail.  I should have been skipped. I'm on MacOSX!!!.
    <false> is not true.

    4 tests, 4 assertions, 1 failures, 0 errors


    % ruby platform-filter-test.rb --name='/test_(?!skip_darwin)/'
    Loaded suite platform-filter-test
    Started
    ...
    Finished in 0.000426 seconds.

    3 tests, 3 assertions, 0 failures, 0 errors

Its not very robust by any stretch of the imagination but if you want to skip
certain methods, regexp on the method names will work.  

enjoy,

-jeremy

-- 
========================================================================
 Jeremy Hinegardner                              jeremy / hinegardner.org