Skip to content

Commit

Permalink
Merge commit 'matthewruby/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlarsen committed Apr 22, 2009
2 parents 40b12ab + d323ef8 commit fa369bf
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
1 change: 0 additions & 1 deletion Manifest.txt
Expand Up @@ -4,7 +4,6 @@ Manifest.txt
PostInstall.txt
README.txt
Rakefile
Ruby DocTest.tmproj
bin/rubydoctest
config/hoe.rb
config/requirements.rb
Expand Down
6 changes: 6 additions & 0 deletions bin/rubydoctest
Expand Up @@ -25,6 +25,7 @@ USAGE: rubydoctest [options] <files>
--trace - turn backtrace on to debug Ruby DocTest
--debugger - include ruby-debug library / gem
--verbose - print more (useful only with --plain)
--require=</path/to/require>,</another/path/to/require> - eg. --require=config/environment.rb
See http://github.com/tablatom/rubydoctest/wikis for more information.
DIRECTIONS
Expand All @@ -33,6 +34,11 @@ end

requires = ['rubygems', File.dirname(__FILE__) + "/../lib/rubydoctest"]
requires << 'ruby-debug' if options.include?("--debugger")

if options.detect {|opt| opt =~ /^--require=(.+)/}
requires << $1.split(",")
end

ruby_lines = []
ruby_lines << "RubyDocTest.trace = true;" if options.include?("--trace")
ruby_lines << "RubyDocTest.verbose = true;" if options.include?("--verbose") or options.include?("-v")
Expand Down
2 changes: 1 addition & 1 deletion doc/special_directives.doctest
Expand Up @@ -12,7 +12,7 @@ This directive splits your irb sessions into logical "test units" with descripti

doctest: This is the first test. Is this document up to date with the code?
>> RubyDocTest::SpecialDirective::NAMES
=> ["doctest:", "!!!", "doctest_require:"]
=> ["doctest:", "it:", "!!!", "doctest_require:"]

Any irb sessions appearing before the first doctest: directive will be included in an all-encompassing "Default Test". If you have no "doctest:" directives anywhere in your document, then all irb statements will be placed in the "Default Test".

Expand Down
17 changes: 16 additions & 1 deletion lib/runner.rb
Expand Up @@ -306,7 +306,7 @@ def organize_blocks(groups = @groups)
current_statements = []
when SpecialDirective
case g.name
when "doctest:"
when "doctest:", "it:"
blocks << CodeBlock.new(current_statements) unless current_statements.empty?
current_statements = []
blocks << g
Expand Down Expand Up @@ -368,6 +368,18 @@ def require_relative_to_file_name(file_name, relative_to)
#
# >> r.tests.first.code_blocks.size
# => 2
#
# doctest: When using the "it:" directive, it should re-append "it" to the description;
# >> r = RubyDocTest::Runner.new("it: should behave\n>> t = 1\n>> t + 2\n=> 3\n>> u = 1", "test.doctest")
# >> r.prepare_tests
# >> r.tests.size
# => 1
#
# >> r.tests.first.description
# => "it should behave"
#
# >> r.tests.first.code_blocks.size
# => 2
def organize_tests(blocks = @blocks)
tests = []
assigned_blocks = nil
Expand All @@ -381,6 +393,9 @@ def organize_tests(blocks = @blocks)
when "doctest:"
assigned_blocks = []
tests << Test.new(g.value, assigned_blocks)
when "it:"
assigned_blocks = []
tests << Test.new("it #{g.value}", assigned_blocks)
when "!!!"
tests << g
end
Expand Down
12 changes: 11 additions & 1 deletion lib/special_directive.rb
Expand Up @@ -5,7 +5,7 @@

module RubyDocTest
class SpecialDirective < Lines
NAMES = ["doctest:", "!!!", "doctest_require:"]
NAMES = ["doctest:", "it:", "!!!", "doctest_require:"]
NAMES_FOR_RX = NAMES.map{ |n| Regexp.escape(n) }.join("|")

# === Test
Expand All @@ -14,6 +14,11 @@ class SpecialDirective < Lines
# >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"])
# >> s.name
# => "doctest:"
#
# doctest: "it:" is a valid directive
# >> s = RubyDocTest::SpecialDirective.new(["it: should test stuff"])
# >> s.name
# => "it:"
def name
if m = lines.first.match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})/)
m[1]
Expand All @@ -35,6 +40,11 @@ def name
# >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", " On Two Lines"])
# >> s.value
# => "Testing Stuff\nOn Two Lines"
#
# doctest: "it" should also work as a directive
# >> s = RubyDocTest::SpecialDirective.new(["it: should do something"])
# >> s.value
# => "should do something"
def value
if m = lines.join("\n").match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})(.*)/m)
m[2].strip
Expand Down
52 changes: 46 additions & 6 deletions rubydoctest.gemspec
@@ -1,18 +1,58 @@
Gem::Specification.new do |s|
s.name = %q{rubydoctest}
s.version = "1.0.0"
s.name = "rubydoctest"
s.version = "1.0.2"

s.specification_version = 2 if s.respond_to? :specification_version=

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Duane Johnson", "Tom Locke", "Dr Nic Williams"]
s.date = %q{2008-06-21}
s.default_executable = %q{rubydoctest}
s.description = %q{Ruby version of Python's doctest tool, but a bit different.}
s.date = "2008-12-06"
s.default_executable = "rubydoctest"
s.description = "Ruby version of Python's doctest tool, but a bit different."
s.email = ["duane.johnson@gmail.com"]
s.executables = ["rubydoctest"]
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "website/index.txt"]
s.files = IO.read("Manifest.txt").split("\n")
manifest = <<-MANIFEST
History.txt
License.txt
Manifest.txt
PostInstall.txt
README.txt
Rakefile
bin/rubydoctest
config/hoe.rb
config/requirements.rb
lib/code_block.rb
lib/doctest_require.rb
lib/lines.rb
lib/result.rb
lib/rubydoctest.rb
lib/rubydoctest/version.rb
lib/runner.rb
lib/special_directive.rb
lib/statement.rb
lib/test.rb
rubydoctest.gemspec
script/console
script/destroy
script/generate
script/rstakeout
script/txt2html
setup.rb
tasks/deployment.rake
tasks/doctests.rake
tasks/environment.rake
tasks/website.rake
textmate/DocTest (Markdown).textmate
textmate/DocTest (Ruby).textmate
textmate/DocTest (Text).textmate
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
website/template.html.erb
MANIFEST
s.files = manifest.strip.split("\n").map{|m| m.strip}
s.has_rdoc = true
s.homepage = %q{http://rubydoctest.rubyforge.org}
s.post_install_message = %q{
Expand Down

0 comments on commit fa369bf

Please sign in to comment.