docu 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
 - data/EXAMPLE_README.md +5 -0
 - data/EXAMPLE_README.md.docu +7 -0
 - data/Gemfile +4 -0
 - data/README.md +34 -0
 - data/Rakefile +6 -0
 - data/bin/docu +5 -0
 - data/docu.gemspec +22 -0
 - data/lib/docu.rb +3 -0
 - data/lib/docu/executes_examples.rb +38 -0
 - data/lib/docu/version.rb +3 -0
 - data/spec/docu/executes_examples_spec.rb +85 -0
 - metadata +70 -0
 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            docu
         
     | 
| 
      
 2 
     | 
    
         
            +
            ====
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Executes code examples you may have in your readme files!
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Example README.md.docu
         
     | 
| 
      
 7 
     | 
    
         
            +
            ----------------------
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ```
         
     | 
| 
      
 10 
     | 
    
         
            +
            Hello!
         
     | 
| 
      
 11 
     | 
    
         
            +
            ======
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            :example:
         
     | 
| 
      
 14 
     | 
    
         
            +
            1 + 1000
         
     | 
| 
      
 15 
     | 
    
         
            +
            #=> 1001
         
     | 
| 
      
 16 
     | 
    
         
            +
            :end:
         
     | 
| 
      
 17 
     | 
    
         
            +
            ```
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            This file will generate a README.md that looks like this:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ```
         
     | 
| 
      
 22 
     | 
    
         
            +
            Hello!
         
     | 
| 
      
 23 
     | 
    
         
            +
            ======
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            1 + 1000
         
     | 
| 
      
 26 
     | 
    
         
            +
            #=> 1001
         
     | 
| 
      
 27 
     | 
    
         
            +
            ```
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            It will also fail if any assertions don't match up.
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            Usage
         
     | 
| 
      
 32 
     | 
    
         
            +
            -----
         
     | 
| 
      
 33 
     | 
    
         
            +
            gem install docu
         
     | 
| 
      
 34 
     | 
    
         
            +
            docu README.md.docu
         
     | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/docu
    ADDED
    
    
    
        data/docu.gemspec
    ADDED
    
    | 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- encoding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            $:.push File.expand_path("../lib", __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "docu/version"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |s|
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.name        = "docu"
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.version     = Docu::VERSION
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.authors     = ["Andrew Vos"]
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.email       = ["andrew.vos@gmail.com"]
         
     | 
| 
      
 10 
     | 
    
         
            +
              s.homepage    = ""
         
     | 
| 
      
 11 
     | 
    
         
            +
              s.summary     = %q{}
         
     | 
| 
      
 12 
     | 
    
         
            +
              s.description = %q{}
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              s.rubyforge_project = "docu"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              s.files         = `git ls-files`.split("\n")
         
     | 
| 
      
 17 
     | 
    
         
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         
     | 
| 
      
 18 
     | 
    
         
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              s.require_paths = ["lib"]
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              s.add_development_dependency "minitest"
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/docu.rb
    ADDED
    
    
| 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Docu
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ExecutesExamples
         
     | 
| 
      
 3 
     | 
    
         
            +
                def initialize output
         
     | 
| 
      
 4 
     | 
    
         
            +
                  @output = output
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def execute path
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @output.puts "Executing Examples"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  errors = []
         
     | 
| 
      
 10 
     | 
    
         
            +
                  successes = 0
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  contents = File.read(path)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  contents.scan(/:example:((?:(?!^:end:).)*)/m).flatten.each do |example|
         
     | 
| 
      
 14 
     | 
    
         
            +
                    if example.include?("#=>")
         
     | 
| 
      
 15 
     | 
    
         
            +
                        expected = example.scan(/#=>\s*(.*)/).first.first
         
     | 
| 
      
 16 
     | 
    
         
            +
                        actual = eval(example).inspect
         
     | 
| 
      
 17 
     | 
    
         
            +
                      if actual == expected
         
     | 
| 
      
 18 
     | 
    
         
            +
                        successes += 1
         
     | 
| 
      
 19 
     | 
    
         
            +
                      else
         
     | 
| 
      
 20 
     | 
    
         
            +
                        errors << "Assertion does not match example. Expected \"#{actual}\" to equal \"#{expected}\""
         
     | 
| 
      
 21 
     | 
    
         
            +
                      end
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  @output.puts "#{errors.size} example(s) failed, #{successes} example(s) passed"
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  if errors.any?
         
     | 
| 
      
 28 
     | 
    
         
            +
                    errors.each do |error|
         
     | 
| 
      
 29 
     | 
    
         
            +
                      @output.puts error
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  else
         
     | 
| 
      
 32 
     | 
    
         
            +
                    File.open(path.chomp(File.extname(path)), "w") do |file|
         
     | 
| 
      
 33 
     | 
    
         
            +
                      file.write contents.gsub(":example:\n", "").gsub(":end:\n", "")
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/docu/version.rb
    ADDED
    
    
| 
         @@ -0,0 +1,85 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../../lib")))
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "docu"
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require "minitest/pride"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "minitest/autorun"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "minitest/spec"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            module Docu
         
     | 
| 
      
 9 
     | 
    
         
            +
              class OutputSpy
         
     | 
| 
      
 10 
     | 
    
         
            +
                attr_accessor :output
         
     | 
| 
      
 11 
     | 
    
         
            +
                def puts(*a)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @output ||= []
         
     | 
| 
      
 13 
     | 
    
         
            +
                  a.each do |i|
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @output << i
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              describe ExecutesExamples do
         
     | 
| 
      
 20 
     | 
    
         
            +
                after do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  File.delete("TEST_README.md") if File.exist?("TEST_README.md")
         
     | 
| 
      
 22 
     | 
    
         
            +
                  File.delete("TEST_README.md.docu") if File.exist?("TEST_README.md.docu")
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                it "writes out some text" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  output_spy = OutputSpy.new
         
     | 
| 
      
 27 
     | 
    
         
            +
                  File.open("TEST_README.md.docu", "w") do |file|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    file.puts
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
         
     | 
| 
      
 31 
     | 
    
         
            +
                  output_spy.output.must_include "Executing Examples"
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                describe "one failing example and one passing example" do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 36 
     | 
    
         
            +
                    File.open("TEST_README.md.docu", "w") do |file|
         
     | 
| 
      
 37 
     | 
    
         
            +
                      file.puts ":example:"
         
     | 
| 
      
 38 
     | 
    
         
            +
                      file.puts "1 + 1"
         
     | 
| 
      
 39 
     | 
    
         
            +
                      file.puts "#=> 23"
         
     | 
| 
      
 40 
     | 
    
         
            +
                      file.puts ":end:"
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                      file.puts ":example:"
         
     | 
| 
      
 43 
     | 
    
         
            +
                      file.puts "1 + 1"
         
     | 
| 
      
 44 
     | 
    
         
            +
                      file.puts "#=> 2"
         
     | 
| 
      
 45 
     | 
    
         
            +
                      file.puts ":end:"
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  it "mentions failure and success" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                    output_spy = OutputSpy.new
         
     | 
| 
      
 51 
     | 
    
         
            +
                    Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
         
     | 
| 
      
 52 
     | 
    
         
            +
                    output_spy.output.must_include "1 example(s) failed, 1 example(s) passed"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  it "outputs errors" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    output_spy = OutputSpy.new
         
     | 
| 
      
 57 
     | 
    
         
            +
                    Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
         
     | 
| 
      
 58 
     | 
    
         
            +
                    output_spy.output.must_include "Assertion does not match example. Expected \"2\" to equal \"23\""
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                  it "does not write the file" do
         
     | 
| 
      
 62 
     | 
    
         
            +
                    File.exist?("TEST_README.md").must_equal false
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                describe "one passing example" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 68 
     | 
    
         
            +
                    File.open("TEST_README.md.docu", "w") do |file|
         
     | 
| 
      
 69 
     | 
    
         
            +
                      file.puts ":example:"
         
     | 
| 
      
 70 
     | 
    
         
            +
                      file.puts "1 + 1"
         
     | 
| 
      
 71 
     | 
    
         
            +
                      file.puts "#=> 2"
         
     | 
| 
      
 72 
     | 
    
         
            +
                      file.puts ":end:"
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  it "writes out the file removing all :example: and :end: markers" do
         
     | 
| 
      
 77 
     | 
    
         
            +
                    output_spy = OutputSpy.new
         
     | 
| 
      
 78 
     | 
    
         
            +
                    Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
         
     | 
| 
      
 79 
     | 
    
         
            +
                    File.exist?("TEST_README.md").must_equal true
         
     | 
| 
      
 80 
     | 
    
         
            +
                    contents = File.read("TEST_README.md").to_s
         
     | 
| 
      
 81 
     | 
    
         
            +
                    contents.must_equal "1 + 1\n#=> 2\n"
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,70 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: docu
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Andrew Vos
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-11-23 00:00:00.000000000Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 15 
     | 
    
         
            +
              name: minitest
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &70328576592840 !ruby/object:Gem::Requirement
         
     | 
| 
      
 17 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 19 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 22 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 23 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *70328576592840
         
     | 
| 
      
 25 
     | 
    
         
            +
            description: ''
         
     | 
| 
      
 26 
     | 
    
         
            +
            email:
         
     | 
| 
      
 27 
     | 
    
         
            +
            - andrew.vos@gmail.com
         
     | 
| 
      
 28 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 29 
     | 
    
         
            +
            - docu
         
     | 
| 
      
 30 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 31 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            files:
         
     | 
| 
      
 33 
     | 
    
         
            +
            - .gitignore
         
     | 
| 
      
 34 
     | 
    
         
            +
            - EXAMPLE_README.md
         
     | 
| 
      
 35 
     | 
    
         
            +
            - EXAMPLE_README.md.docu
         
     | 
| 
      
 36 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 37 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 38 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 39 
     | 
    
         
            +
            - bin/docu
         
     | 
| 
      
 40 
     | 
    
         
            +
            - docu.gemspec
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/docu.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/docu/executes_examples.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/docu/version.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            - spec/docu/executes_examples_spec.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            homepage: ''
         
     | 
| 
      
 46 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 47 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 48 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 49 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 50 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 51 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 52 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 53 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 54 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 55 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 56 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 57 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 58 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 59 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 60 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 61 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 62 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 63 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 64 
     | 
    
         
            +
            rubyforge_project: docu
         
     | 
| 
      
 65 
     | 
    
         
            +
            rubygems_version: 1.8.10
         
     | 
| 
      
 66 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 67 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 68 
     | 
    
         
            +
            summary: ''
         
     | 
| 
      
 69 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 70 
     | 
    
         
            +
            - spec/docu/executes_examples_spec.rb
         
     |