docspec 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8a5c9b5152aec40381604f7b29473d9df865cba3cd650cd1b70dda2115e9165
4
- data.tar.gz: 618428c8f9733ee701f6e2fb4babd5c1da39e85c0db601ae8b0f07e9f942e864
3
+ metadata.gz: 7f995211f9a696fc2d183baf3f9e4e36eea49138eb284dc131538bd091155c0b
4
+ data.tar.gz: d9ab2eed21925c84af410ab1f8738b284cd46c828b7b839edd1665b6e590673f
5
5
  SHA512:
6
- metadata.gz: 2a2eacb5a463a059419863bf58676146b73e9398c5ec94563e444525865764bf2ba1814bc4cdb9980983a1314d7c8951c3be0b23f7cb3a6a4b7e312d46761164
7
- data.tar.gz: 5de5e31541b08ba45594da601462db482b6c677eae357026b75678fb0d50dbaad861f4e86e339f2dbcdd5760fc13ae22f47d4577e39e604be83e971ef598e75a
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 a folder using the CLI class
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
- #=> 6 tests, 0 failed
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 "hello":String>
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
- if Gem.loaded_specs.has_key?('simplecov') && !ENV['DISABLE_SIMPLECOV']
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 ARGV[0]
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
- attr_reader :target, :exit_code, :total_examples, :failed_examples
5
+ include Colsole
7
6
 
8
- def initialize(target = nil)
9
- @target = target || 'README.md'
10
- end
7
+ attr_reader :targets, :exit_code, :total_examples, :failed_examples
11
8
 
12
- def mode
13
- File.directory?(target) ? :dir : :file
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
- if mode == :dir
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 run_dir
35
- all_success = true
36
- Dir["#{target}/**/*.md"].sort.each do |file|
37
- say ''
38
- say "c`file : #{file}`"
39
- success = run_file file
40
- all_success = false unless success
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
 
@@ -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
- actual == expected
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
- eval full_code
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
@@ -0,0 +1,14 @@
1
+ module Docspec
2
+ module StringRefinements
3
+ refine String do
4
+ def ellipses_match?(other)
5
+ str = self
6
+
7
+ str = str[3..-1] if str.start_with?('...')
8
+ str = str[0..-4] if str.end_with?('...')
9
+
10
+ other.include?(str)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Docspec
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/docspec.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'byebug' if ENV['BYEBUG']
1
+ require 'docspec/refinements'
2
2
 
3
+ require 'docspec/testable'
3
4
  require 'docspec/output_capturer'
5
+
4
6
  require 'docspec/example'
5
- require 'docspec/testable'
6
7
  require 'docspec/document'
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.1.3
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: 2023-03-17 00:00:00.000000000 Z
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: '2.7'
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.4.8
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: []