This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Yippy Skippy
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Work on Sapphire continues. In addition to more tests and light refactoring in general, I've finally gotten a skip assertion added into Test::Unit that lets you skip tests based for various reasons.
This was the old way of doing things:
unless CONFIG['host_os'] =~ /mswin/i
def test_something
assert_equal(1, @obj.unix_method)
end
end
It's not just cosmetic. In addition to the ability to inline a skip method, there are hooks for checking and dealing with skip methods internally, so different UI runners can handle skipped tests differently.
Also, and this is my favorite bit, skipped tests are now tallied separately. In the old code, you wouldn't see test_something counted as a test because it failed the conditional block test. In a few cases that meant adding stub test methods so that Test::Unit wouldn't complain if there were no test methods found.
With the new approach, you'll now see output like this:
Loaded suite tc_some_test
Started
.S..S..
Finished in 0.0 seconds.
7 tests, 12 assertions, 0 failures, 0 errors, 2 skipped
You'll see the actual test count, the number of tests that were skipped, and an 'S' in the test runner, giving you a visual indicator that a test was skipped.
With this in place it's also easy to add helper functions that can be mixed in, so I can generalize my skip's like so:
include Test::Helper
...
skip_windows
skip_unless_root
skip_if_jruby
This was a super bitch to add, btw. It required the addition of a new class, and the modification of at least five other files on top of figuring out all the various hooks and interactions that were going on behind the scenes.