Skip to content

Instantly share code, notes, and snippets.

@acook
Last active October 12, 2015 17:17
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 acook/fd70f085342e451d0e68 to your computer and use it in GitHub Desktop.
Save acook/fd70f085342e451d0e68 to your computer and use it in GitHub Desktop.
class Foo
end
__END__ unless __FILE__ == $0
raise 'I pity the Foo' unless Foo.name == 'Foo'

#!/usr/bin/env litrb run

Builtin Testing with literate Ruby!

First we create an empty class to test.

class Foo
end

Now we define a test for the above code block.

spec 'I pity the Foo' { Foo.name == 'Foo' }

Important things to note:

  • When the program is run normally (with litrb run file.rb) all ~~~ blocks are concatenated and run, ignoring everything else.
  • When we run tests (with litrb test file.rb) it will load the ~~~ blocks as above and then run the > blocks in a namespaced DSL.
  • When we generate docs (with litrb docs file.rb) it will generate nice HTML docs from the literate markdown file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment