02
Apr
10

Focused unit tests in ruby 1.9

I was having a problem running focused unit tests with TextMate 1.5.9, ruby 1.9.1 and rails 2.3.5. TextMate passes the params to the script like this:

ruby unit/booking_test.rb --name=test_cost_is_calculated_correctly_when_theres_a_surcharge

This doesn’t work (all tests are run instead) because the parameter is not passed correctly to the script. This works, however:

ruby unit/booking_test.rb --name test_cost_is_calculated_correctly_when_theres_a_surcharge

On ruby 1.8.7 both ways of passing the argument work just fine, while on ruby 1.9.1 only the second way works.

Since we want to pass two arguments to the script (‘––name’, ‘test_foobar’) instead of one (‘––name=test_foobar’), let’s patch TextMate. Open
/Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/runscript.rb
and replace

if name and !name.empty?
args << "--name #{name}"
elsif test_name and !test_name.empty?
args << "--name test_#{test_name.gsub(/\s+/,'_')}"
elsif spec and !spec.empty? and context and !context.empty?
args << %Q{--name "/test_spec \\{.*#{context}\\} \\d{3} \\[#{spec}\\]/"}

with

args << "--name"
if name and !name.empty?
args << name
elsif test_name and !test_name.empty?
args << "test_#{test_name.gsub(/\s+/,'_')}"
elsif spec and !spec.empty? and context and !context.empty?
args << %Q{"/test_spec \\{.*#{context}\\} \\d{3} \\[#{spec}\\]/"}

This will make the focused unit tests work.

Advertisement

0 Responses to “Focused unit tests in ruby 1.9”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.