Code Climate Build Status

Doctest::Core

Extract doctests from your ruby files

Installation

Add this line to your application's Gemfile:

gem 'doctest-core'

And then execute:

$ bundle

Or install it yourself as:

$ gem install doctest-core

Usage

Add doctest-comments to your ruby files:

class ClassWithDoctests

  # Always returns 'a'
  #
  # >> ClassWithDoctests.a
  # => 'a'
  def self.a
    'a'
  end

  # Always returns 'b'
  #
  # >> ClassWithDoctests.b
  # => 'b'
  def self.b
    'b'
  end

end

You can then run

Doctest::Core.extract_from(ClassWithDoctests)

to get a simple array of doctest occurrences. Those contain

  • code_string: The source code string ('ClassWithDoctests.a')
  • result_string: The result code string ('b')
  • original_file: The source location of the file that contains the doctest
  • line: The line number of the doctest occurrence

You can also access code_evaluation and result_evaluation for the results of the both code blocks.

Those results can be used to implement test framework-specific gems.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request