minitest-markdown 0.0.1.pre → 0.1.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6836d7576d3a208628f401e2660fac20d4288faf95c6513e76dd20a2a402fed2
4
- data.tar.gz: 4f38166f7ff54f9a74391daafe8e698a7f0aabc57cf7a3797f292b3b8d85d524
3
+ metadata.gz: c4e1e286d2eead001d4b6e0d361aa9bb5c0a7019a5eb8d72eacf6635003e59da
4
+ data.tar.gz: 3f95349b886aa8752280e2fb2b5083d5bfc754ec8c4faed065dbb2a6e9b4d7e5
5
5
  SHA512:
6
- metadata.gz: 393bc3aff42df19c5cfd10c2edddb64242798765d30aed3185e44be621547e0ed93f495113cca4082e388ab20f2da213f4f5ad4411b17f6117b1421c531d066a
7
- data.tar.gz: a30d096c73f2064311cb2d729305fe5cc1d00cca871575fb75783d8046d28f5fc325d92882ccb886834358ed6a586f36eb397439829fba22f4d875c2f6e61998
6
+ metadata.gz: cd12cc6d7df1724100119b6e03e5960411d7d83b4de26beb0d4bbde0cc3e3f7a66e94901e5f99f051a82f70e058ffa1b103ee0726d103765bb9c405d661387e1
7
+ data.tar.gz: 11a4a61ba9044aec6811b9df724a111fa5345b29d837d91c8ee76a73e95939ca760243423e40127597d3b3ea0f040e633e31001d4268f33c8e06b5545efa0e06
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.0.pre] - 2025-05-01
4
+
5
+ - Add ability to pass stubs to test class
6
+ - Add dependency; minitest-stub_any_instance
7
+
3
8
  ## [0.0.1.pre] - 2025-04-24
4
9
 
5
10
  - Bump minitest dep to >= 5.25.2
data/README.md CHANGED
@@ -30,7 +30,7 @@ To test the Ruby blocks in your README file, create file `test_readme.rb` (for e
30
30
  require 'minitest/autorun' # or in your test_helper
31
31
  require 'minitest/markdown' # ditto
32
32
 
33
- class ReadmeTest < MyTest # your own subclass of Minitest::Test
33
+ class ReadmeTest < Minitest::Test # or your own subclass of Minitest::Test
34
34
  Markdown.generate_markdown_tests(self)
35
35
  end
36
36
  # => nil
@@ -101,6 +101,34 @@ The hook methods defined in the [minitest-hooks](https://github.com/jeremyevans/
101
101
 
102
102
  Everything in the code blocks above runs as test code. [minitest-proveit](https://github.com/seattlerb/minitest-proveit) would complain otherwise ;-)
103
103
 
104
+ ## Stubbing
105
+
106
+ It is possible to pass stubs to the generated tests. This is done by passing a hash of procs using the stubs keyword. Hash keys represent the index of the text code block and the key is a proc which is called around the relevant test code. 2 convenience methods are provided by the `Markdown::Stubb` module. In your markdown test:
107
+ ```ruby
108
+ class MarkdownTest < Minitest::Test
109
+ extend Markdown::Stubb # for the stubb & stubb_any_instance methods
110
+
111
+ stubs = {}
112
+ stubs[8] = stubb(Set, :new, []) # returns a proc
113
+ stubs[9] = stubb_any_instance(Set, :size, 42) # uses the bundled `minitest-stub_any_instance` extension
114
+
115
+ Markdown.generate_markdown_tests(self, stubs: stubs)
116
+ end
117
+ # => nil
118
+ ```
119
+ The 2 stubs above are demonstated in the following examples:
120
+ ```ruby
121
+ # This is test_block8
122
+ Set.new([1, 'c', :s]) # Set.new stubbed to return an Array
123
+ # => instance_of Array
124
+ ```
125
+ ```ruby
126
+ # This is test_block9
127
+ Set.new([1, 'c', :s]).size # Set#size stubbed to return 42
128
+ # => 42
129
+ ```
130
+ Presently only one stub per test is possible.
131
+
104
132
  ## Configuration
105
133
 
106
134
  No configuation is required if you use Bundler. If not, set your `project_root` path using the setter method:
@@ -120,7 +148,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
120
148
 
121
149
  ## Contributing
122
150
 
123
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/minitest-markdown. Please checkout a suitably named branch before submitting a PR.
151
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/matzfan/minitest-markdown. Please checkout a suitably named branch before submitting a PR.
124
152
 
125
153
  ## License
126
154
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ module Markdown
5
+ # a proc'ed stub
6
+ module Stubb
7
+ def stubb(object, method, ret_val, *args, **kwargs)
8
+ proc { |&blk| object.stub(method, ret_val, *args, **kwargs) { blk.call } }
9
+ end
10
+
11
+ def stubb_any_instance(object, method, ret_val, *args, **kwargs)
12
+ proc { |&blk| object.stub_any_instance(method, ret_val, *args, **kwargs) { blk.call } }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -20,9 +20,9 @@ module Minitest
20
20
  @ruby_blocks = parse_ruby_blocks
21
21
  end
22
22
 
23
- def define_methods
23
+ def define_methods(stubs: {})
24
24
  define_non_test_methods
25
- @ruby_blocks.each_with_index { |block, i| define_test_method(block, i) }
25
+ @ruby_blocks.each_with_index { |block, i| define_test_method(block, i, stubs[i]) }
26
26
  nil
27
27
  end
28
28
 
@@ -59,10 +59,13 @@ module Minitest
59
59
  @ruby_blocks.delete(blocks.first).fenced_block_str # hook method blocks can't be test methods
60
60
  end
61
61
 
62
- def define_test_method(block, meth_index)
62
+ def define_test_method(block, meth_index, stub = nil)
63
+ stub ||= proc { |&blk| blk.call } # empty proc if no stub provided
63
64
  instance = self # scope
64
65
  klass.define_method(:"test_block#{meth_index}") do
65
- block.assertions.each { |assertion_hash| instance.send(:evaluation_assertions, assertion_hash, binding) }
66
+ stub.call do
67
+ block.assertions.each { |assertion_hash| instance.send(:evaluation_assertions, assertion_hash, binding) }
68
+ end
66
69
  end
67
70
  end
68
71
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minitest
4
4
  module Markdown
5
- VERSION = '0.0.1.pre'
5
+ VERSION = '0.1.0.pre'
6
6
  end
7
7
  end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'minitest/stub_any_instance'
4
+
3
5
  require_relative 'markdown/configuration'
4
6
  require_relative 'markdown/error'
7
+ require_relative 'markdown/stubb'
5
8
  require_relative 'markdown/version'
6
9
  require_relative 'markdown/test_class'
7
10
 
@@ -17,8 +20,8 @@ module Minitest
17
20
  yield config
18
21
  end
19
22
 
20
- def generate_markdown_tests(klass, path: nil)
21
- TestClass.new(klass, path: path).define_methods
23
+ def generate_markdown_tests(klass, path: nil, stubs: {})
24
+ TestClass.new(klass, path: path).define_methods(stubs: stubs)
22
25
  end
23
26
  end
24
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.1.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - MatzFan
@@ -49,6 +49,20 @@ dependencies:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: 5.25.2
52
+ - !ruby/object:Gem::Dependency
53
+ name: minitest-stub_any_instance
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '1.0'
59
+ type: :runtime
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '1.0'
52
66
  description: Generates tests for Ruby code blocks in any Markdown file.
53
67
  executables: []
54
68
  extensions: []
@@ -64,6 +78,7 @@ files:
64
78
  - lib/minitest/markdown.rb
65
79
  - lib/minitest/markdown/configuration.rb
66
80
  - lib/minitest/markdown/error.rb
81
+ - lib/minitest/markdown/stubb.rb
67
82
  - lib/minitest/markdown/test_class.rb
68
83
  - lib/minitest/markdown/test_code_block.rb
69
84
  - lib/minitest/markdown/version.rb
@@ -89,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  - !ruby/object:Gem::Version
90
105
  version: '0'
91
106
  requirements: []
92
- rubygems_version: 3.6.7
107
+ rubygems_version: 3.6.8
93
108
  specification_version: 4
94
109
  summary: Turn your README.md Ruby code blocks into testable code.
95
110
  test_files: []