Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created June 8, 2012 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/2896930 to your computer and use it in GitHub Desktop.
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.
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