Written November 19, 2007. Tagged Ruby, Ruby on Rails.
If you're a bad boy and sometimes write tests after the code you're testing, here's a quick tip:
It's nice to be able to glance at the code being tested while writing the tests. When working e.g. with Rails, the tests and the code are typically in different files.
Copy the code being tested. Paste it at the bottom of the test file, under an END
line, and it will in effect be commented out (it actually goes into the DATA global constant).
So while writing a test, your buffer may now look like so:
require File.dirname(__FILE__) + '/../test_helper'
class MyTest < Test::Unit::TestCase
def test_something
# TODO
end
end
__END__
# This stuff is in effect commented out.
def something(input)
"hah!"
end
I remove the END
and everything after it once the test has been written.