docspec 0.1.3 → 0.2.0
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.
- checksums.yaml +4 -4
 - data/README.md +17 -4
 - data/bin/docspec +3 -2
 - data/lib/docspec/cli.rb +22 -22
 - data/lib/docspec/example.rb +9 -5
 - data/lib/docspec/refinements.rb +14 -0
 - data/lib/docspec/version.rb +1 -1
 - data/lib/docspec.rb +3 -2
 - metadata +11 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7f995211f9a696fc2d183baf3f9e4e36eea49138eb284dc131538bd091155c0b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d9ab2eed21925c84af410ab1f8738b284cd46c828b7b839edd1665b6e590673f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4d1b6ba6f8dba292df58c9b381afd69b7205c534bc9adb7a42aabdc623fb2537f9798e9d4855fc8f57a0858bd486030d329d53d56c96442e0afd3b0999393f34
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 66aff11ef3b75ff2633c083f9adfdca2d3639223f55caf081fcbcd2d586b16f60a29e8889ceb8f33da85199bf977b915be92ab44f69af79d885a069dc2eb7590
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -68,6 +68,7 @@ puts document.success? 
     | 
|
| 
       68 
68 
     | 
    
         
             
            # Test a file using the CLI class
         
     | 
| 
       69 
69 
     | 
    
         
             
            runner = Docspec::CLI.new 'test/sample.md'
         
     | 
| 
       70 
70 
     | 
    
         
             
            success = runner.run
         
     | 
| 
      
 71 
     | 
    
         
            +
            #=> file : test/sample.md
         
     | 
| 
       71 
72 
     | 
    
         
             
            #=> pass : Sample Test
         
     | 
| 
       72 
73 
     | 
    
         
             
            #=> 
         
     | 
| 
       73 
74 
     | 
    
         
             
            #=> 1 tests, 0 failed
         
     | 
| 
         @@ -75,8 +76,8 @@ success = runner.run 
     | 
|
| 
       75 
76 
     | 
    
         | 
| 
       76 
77 
     | 
    
         | 
| 
       77 
78 
     | 
    
         
             
            ```ruby
         
     | 
| 
       78 
     | 
    
         
            -
            # Test  
     | 
| 
       79 
     | 
    
         
            -
            runner = Docspec::CLI.new 'test'
         
     | 
| 
      
 79 
     | 
    
         
            +
            # Test multiple folders/files using the CLI class
         
     | 
| 
      
 80 
     | 
    
         
            +
            runner = Docspec::CLI.new 'test', 'test/sample.md'
         
     | 
| 
       80 
81 
     | 
    
         
             
            success = runner.run
         
     | 
| 
       81 
82 
     | 
    
         
             
            #=> file : test/folder/another.md
         
     | 
| 
       82 
83 
     | 
    
         
             
            #=> pass : Another Sample Test
         
     | 
| 
         @@ -89,8 +90,11 @@ success = runner.run 
     | 
|
| 
       89 
90 
     | 
    
         
             
            #=> void : echo shell
         
     | 
| 
       90 
91 
     | 
    
         
             
            #=> pass : puts "ruby"
         
     | 
| 
       91 
92 
     | 
    
         
             
            #=> void : puts "ruby"
         
     | 
| 
      
 93 
     | 
    
         
            +
            #=> 
         
     | 
| 
      
 94 
     | 
    
         
            +
            #=> file : test/sample.md
         
     | 
| 
      
 95 
     | 
    
         
            +
            #=> pass : Sample Test
         
     | 
| 
       92 
96 
     | 
    
         
             
            #=>
         
     | 
| 
       93 
     | 
    
         
            -
            #=>  
     | 
| 
      
 97 
     | 
    
         
            +
            #=> 7 tests, 0 failed
         
     | 
| 
       94 
98 
     | 
    
         | 
| 
       95 
99 
     | 
    
         
             
            ```
         
     | 
| 
       96 
100 
     | 
    
         | 
| 
         @@ -113,7 +117,16 @@ string of that exception: 
     | 
|
| 
       113 
117 
     | 
    
         
             
            ```ruby
         
     | 
| 
       114 
118 
     | 
    
         
             
            # Exceptions are captured
         
     | 
| 
       115 
119 
     | 
    
         
             
            puts "hello".camel_case
         
     | 
| 
       116 
     | 
    
         
            -
            #=> #<NoMethodError: undefined method `camel_case' for  
     | 
| 
      
 120 
     | 
    
         
            +
            #=> #<NoMethodError: undefined method `camel_case' for ...
         
     | 
| 
      
 121 
     | 
    
         
            +
            ```
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            Using three dots at the beginning or end of the expected output (like in the
         
     | 
| 
      
 124 
     | 
    
         
            +
            above example) will perform a partial match:
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 127 
     | 
    
         
            +
            # Ellipsis match
         
     | 
| 
      
 128 
     | 
    
         
            +
            puts "the beginning will be ignored as well as the end"
         
     | 
| 
      
 129 
     | 
    
         
            +
            #=> ... will be ignored ...
         
     | 
| 
       117 
130 
     | 
    
         
             
            ```
         
     | 
| 
       118 
131 
     | 
    
         | 
| 
       119 
132 
     | 
    
         
             
            Your code and expected output can contain multiple lines of code:
         
     | 
    
        data/bin/docspec
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            disabled = ENV['DOCSPEC_NOCOV'] || ENV['NOCOV']
         
     | 
| 
      
 3 
     | 
    
         
            +
            if Gem.loaded_specs.has_key?('simplecov') && !disabled
         
     | 
| 
       3 
4 
     | 
    
         
             
              require 'simplecov'
         
     | 
| 
       4 
5 
     | 
    
         
             
              SimpleCov.configure do
         
     | 
| 
       5 
6 
     | 
    
         
             
                command_name ENV['SIMPLECOV_COMMAND'] || 'Docspec'
         
     | 
| 
         @@ -10,6 +11,6 @@ end 
     | 
|
| 
       10 
11 
     | 
    
         
             
            require 'docspec'
         
     | 
| 
       11 
12 
     | 
    
         
             
            require 'docspec/cli'
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            runner = Docspec::CLI.new 
     | 
| 
      
 14 
     | 
    
         
            +
            runner = Docspec::CLI.new(*ARGV)
         
     | 
| 
       14 
15 
     | 
    
         
             
            success = runner.run
         
     | 
| 
       15 
16 
     | 
    
         
             
            exit success ? 0 : 1
         
     | 
    
        data/lib/docspec/cli.rb
    CHANGED
    
    | 
         @@ -1,48 +1,48 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'colsole'
         
     | 
| 
       2 
     | 
    
         
            -
            include Colsole
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            module Docspec
         
     | 
| 
       5 
4 
     | 
    
         
             
              class CLI
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 5 
     | 
    
         
            +
                include Colsole
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                  @target = target || 'README.md'
         
     | 
| 
       10 
     | 
    
         
            -
                end
         
     | 
| 
      
 7 
     | 
    
         
            +
                attr_reader :targets, :exit_code, :total_examples, :failed_examples
         
     | 
| 
       11 
8 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                def  
     | 
| 
       13 
     | 
    
         
            -
                   
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize(*targets)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  targets = ['README.md'] if targets.empty?
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @targets = targets
         
     | 
| 
       14 
12 
     | 
    
         
             
                end
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
14 
     | 
    
         
             
                def run
         
     | 
| 
       17 
     | 
    
         
            -
                  abort "Target not found: #{target}" unless File.exist? target
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
15 
     | 
    
         
             
                  @exit_code = 0
         
     | 
| 
       20 
16 
     | 
    
         
             
                  @total_examples = 0
         
     | 
| 
       21 
17 
     | 
    
         
             
                  @failed_examples = 0
         
     | 
| 
       22 
18 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                   
     | 
| 
       24 
     | 
    
         
            -
                    run_dir
         
     | 
| 
       25 
     | 
    
         
            -
                  else
         
     | 
| 
       26 
     | 
    
         
            -
                    run_file target
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  targets.each { |target| run_target target }
         
     | 
| 
       28 
20 
     | 
    
         | 
| 
       29 
21 
     | 
    
         
             
                  show_footer
         
     | 
| 
       30 
22 
     | 
    
         
             
                end
         
     | 
| 
       31 
23 
     | 
    
         | 
| 
       32 
24 
     | 
    
         
             
              private
         
     | 
| 
       33 
25 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                def  
     | 
| 
       35 
     | 
    
         
            -
                   
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
      
 26 
     | 
    
         
            +
                def run_target(target)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  abort "Target not found: #{target}" unless File.exist? target
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  if File.directory? target
         
     | 
| 
      
 30 
     | 
    
         
            +
                    run_dir target
         
     | 
| 
      
 31 
     | 
    
         
            +
                  else
         
     | 
| 
      
 32 
     | 
    
         
            +
                    run_file target
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def run_dir(dir)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  Dir["#{dir}/**/*.md"].each do |file|
         
     | 
| 
      
 38 
     | 
    
         
            +
                    run_file file
         
     | 
| 
       41 
39 
     | 
    
         
             
                  end
         
     | 
| 
       42 
     | 
    
         
            -
                  all_success
         
     | 
| 
       43 
40 
     | 
    
         
             
                end
         
     | 
| 
       44 
41 
     | 
    
         | 
| 
       45 
42 
     | 
    
         
             
                def run_file(file)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  say ''
         
     | 
| 
      
 44 
     | 
    
         
            +
                  say "c`file : #{file}`"
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
       46 
46 
     | 
    
         
             
                  document = Docspec::Document.from_file file
         
     | 
| 
       47 
47 
     | 
    
         
             
                  document.test
         
     | 
| 
       48 
48 
     | 
    
         | 
    
        data/lib/docspec/example.rb
    CHANGED
    
    | 
         @@ -3,6 +3,8 @@ require 'diffy' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module Docspec
         
     | 
| 
       4 
4 
     | 
    
         
             
              class Example
         
     | 
| 
       5 
5 
     | 
    
         
             
                include OutputCapturer
         
     | 
| 
      
 6 
     | 
    
         
            +
                using StringRefinements
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       6 
8 
     | 
    
         
             
                attr_reader :code, :type, :before
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
10 
     | 
    
         
             
                def initialize(type:, code:, before: nil)
         
     | 
| 
         @@ -60,7 +62,11 @@ module Docspec 
     | 
|
| 
       60 
62 
     | 
    
         
             
                end
         
     | 
| 
       61 
63 
     | 
    
         | 
| 
       62 
64 
     | 
    
         
             
                def success?
         
     | 
| 
       63 
     | 
    
         
            -
                   
     | 
| 
      
 65 
     | 
    
         
            +
                  if expected.include? '...'
         
     | 
| 
      
 66 
     | 
    
         
            +
                    expected.ellipses_match? actual
         
     | 
| 
      
 67 
     | 
    
         
            +
                  else
         
     | 
| 
      
 68 
     | 
    
         
            +
                    actual == expected
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
       64 
70 
     | 
    
         
             
                end
         
     | 
| 
       65 
71 
     | 
    
         | 
| 
       66 
72 
     | 
    
         
             
              protected
         
     | 
| 
         @@ -68,10 +74,8 @@ module Docspec 
     | 
|
| 
       68 
74 
     | 
    
         
             
                def actual!
         
     | 
| 
       69 
75 
     | 
    
         
             
                  capture_output do
         
     | 
| 
       70 
76 
     | 
    
         
             
                    case type
         
     | 
| 
       71 
     | 
    
         
            -
                    when 'ruby'
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                    when 'shell'
         
     | 
| 
       74 
     | 
    
         
            -
                      puts `#{full_code}`
         
     | 
| 
      
 77 
     | 
    
         
            +
                    when 'ruby' then eval full_code
         
     | 
| 
      
 78 
     | 
    
         
            +
                    when 'shell' then puts `#{full_code}`
         
     | 
| 
       75 
79 
     | 
    
         
             
                    end
         
     | 
| 
       76 
80 
     | 
    
         
             
                  end.strip
         
     | 
| 
       77 
81 
     | 
    
         
             
                end
         
     | 
    
        data/lib/docspec/version.rb
    CHANGED
    
    
    
        data/lib/docspec.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: docspec
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Danny Ben Shitrit
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-07-31 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: colsole
         
     | 
| 
         @@ -58,14 +58,18 @@ files: 
     | 
|
| 
       58 
58 
     | 
    
         
             
            - lib/docspec/document.rb
         
     | 
| 
       59 
59 
     | 
    
         
             
            - lib/docspec/example.rb
         
     | 
| 
       60 
60 
     | 
    
         
             
            - lib/docspec/output_capturer.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/docspec/refinements.rb
         
     | 
| 
       61 
62 
     | 
    
         
             
            - lib/docspec/testable.rb
         
     | 
| 
       62 
63 
     | 
    
         
             
            - lib/docspec/version.rb
         
     | 
| 
       63 
64 
     | 
    
         
             
            homepage: https://github.com/dannyben/docspec
         
     | 
| 
       64 
65 
     | 
    
         
             
            licenses:
         
     | 
| 
       65 
66 
     | 
    
         
             
            - MIT
         
     | 
| 
       66 
67 
     | 
    
         
             
            metadata:
         
     | 
| 
      
 68 
     | 
    
         
            +
              bug_tracker_uri: https://github.com/DannyBen/docspec/issues
         
     | 
| 
      
 69 
     | 
    
         
            +
              changelog_uri: https://github.com/DannyBen/docspec/blob/master/CHANGELOG.md
         
     | 
| 
      
 70 
     | 
    
         
            +
              source_code_uri: https://github.com/DannyBen/docspec
         
     | 
| 
       67 
71 
     | 
    
         
             
              rubygems_mfa_required: 'true'
         
     | 
| 
       68 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 72 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       69 
73 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       70 
74 
     | 
    
         
             
            require_paths:
         
     | 
| 
       71 
75 
     | 
    
         
             
            - lib
         
     | 
| 
         @@ -73,15 +77,15 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       73 
77 
     | 
    
         
             
              requirements:
         
     | 
| 
       74 
78 
     | 
    
         
             
              - - ">="
         
     | 
| 
       75 
79 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       76 
     | 
    
         
            -
                  version: ' 
     | 
| 
      
 80 
     | 
    
         
            +
                  version: '3.1'
         
     | 
| 
       77 
81 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       78 
82 
     | 
    
         
             
              requirements:
         
     | 
| 
       79 
83 
     | 
    
         
             
              - - ">="
         
     | 
| 
       80 
84 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       81 
85 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       82 
86 
     | 
    
         
             
            requirements: []
         
     | 
| 
       83 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
       84 
     | 
    
         
            -
            signing_key: 
     | 
| 
      
 87 
     | 
    
         
            +
            rubygems_version: 3.5.14
         
     | 
| 
      
 88 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       85 
89 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       86 
90 
     | 
    
         
             
            summary: Embedded tests in Markdown documents
         
     | 
| 
       87 
91 
     | 
    
         
             
            test_files: []
         
     |