Skip to content

Instantly share code, notes, and snippets.

@jeremyf
Created July 6, 2012 13:42
Show Gist options
  • Save jeremyf/3060228 to your computer and use it in GitHub Desktop.
Save jeremyf/3060228 to your computer and use it in GitHub Desktop.
Demonstrate in-file testing option for Ruby
# This file demonstrates a quick and dirty means of testing a file.
# Above the ```if __FILE__ == $0``` line is where the "production" code
# is written. Inside the IF block, the "test" code is written.
class Inline
def to_s
'Hello'
end
end
# From Terminal, you can type `ruby class-inline.rb`
#
# The tests below will execute and you will see the tell tail results
# of ruby's test output.
#
# __FILE__ is this file.
# $0 is the file that is running via ruby
#
if __FILE__ == $0
require 'test/unit'
class InlineTest < Test::Unit::TestCase
def test_to_s
assert 'Hello' == Inline.new.to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment