Created
June 8, 2012 17:12
-
-
Save pmarreck/2896930 to your computer and use it in GitHub Desktop.
I put this at the end of my class files so that running the file directly runs the test for the file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Someclass | |
... | |
end | |
########## inline test running | |
if __FILE__==$PROGRAM_NAME | |
require_relative '../path_to_test.rb' | |
end | |
# This will run the relevant test if you run the class file. It will not run that code if the class file is just required from elsewhere, though. | |
#file: path_to_test.rb | |
# This part is also super easy for unit tests... | |
require 'test/unit' | |
class SomeclassTest < Test::Unit::TestCase | |
def setup | |
# setup code | |
end | |
def test_some_feature | |
assert something_is_true, "it's not true!" | |
assert_equal value_youre_expecting, Someclass.new.someemethod("params") | |
# etc. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment