The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Yippy Skippy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Yippy Skippy Posted: Apr 20, 2008 11:05 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
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

Now you can do this:
def test_something
   skip('MS Windows'){ CONFIG['host_os'] =~ /mswin/i }
   assert_equal(1, @obj.unix_method)
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

And so on.

You can see a full example here.

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.

Read: Yippy Skippy

Topic: Visual Rails Workbench Launches On Monday Previous Topic   Next Topic Topic: Blog with OS X Tips and Tricks

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use