yard-doctest 0.1.15 → 0.1.16

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: 723dea9f19d8563896620983b07e9c10c8ffd675fec6c630265dd1b7c9296137
4
- data.tar.gz: fe76d9dee40e4ced8ceaea99cc0b6e985e9dc347e6b74dc373f6d568e8c00bb8
3
+ metadata.gz: c75c418a5cbe791e718cb9ba2deff5f1b187c00ae8578a79d149cda39f567d05
4
+ data.tar.gz: e48f64151a5273ddbbc8d0f8efe5327c2f7798d744473ed7ac82e0b49e1b0842
5
5
  SHA512:
6
- metadata.gz: 222ad5b8623b913c3c16dd7ea76731e9b2b889285f3221c242de8ade6cf55870b09d541d71a9e239611867737306a06f75994f51cc5f39c77cd0c504ff512431
7
- data.tar.gz: 1715dab13e1e08605bda7ed64c61a978c8c6230745470beddd78bba79b8a2f970577d667980b65c4c64109e426e45986efc201387c3a73b6a2525a0a1900088f
6
+ metadata.gz: a6f46775edc0057a440ae41adcc1377a2125015981ac9dc7fd8cc5481754e8f4d4289a66262b7db51489b0ef1039c6dcd12ac825700d5bd22b687f6228979722
7
+ data.tar.gz: 69cfad611e30b3f5cd1fc6f672aed1326efd330cc9e6a8a2124316541431d2adf92b0edb71a2a5404f2b0f0a11fac218eec98f1653b36cb6316b80754f1e4c6a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.16
2
+
3
+ * Pass example instance to hooks to allow for its inspection (thanks @nrser)
4
+
1
5
  ## 0.1.15
2
6
 
3
7
  * Fix an issue when exception is swallowed in assertion phase
@@ -590,6 +590,26 @@ Feature: yard doctest
590
590
  When I run `bundle exec yard doctest`
591
591
  Then the output should contain "2 runs, 2 assertions, 0 failures, 0 errors, 0 skips"
592
592
 
593
+ Scenario: passes example to hooks to allow for inspection
594
+ Given a file named "doctest_helper.rb" with:
595
+ """
596
+ YARD::Doctest.before do |example|
597
+ require example.filepath.split(':').first
598
+ end
599
+ """
600
+ And a file named "app/app.rb" with:
601
+ """
602
+ # @example
603
+ # App.foo #=> 'bar'
604
+ class App
605
+ def self.foo
606
+ 'bar'
607
+ end
608
+ end
609
+ """
610
+ When I run `bundle exec yard doctest`
611
+ Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
612
+
593
613
  Scenario: can skip tests
594
614
  Given a file named "doctest_helper.rb" with:
595
615
  """
@@ -26,12 +26,6 @@ module YARD
26
26
 
27
27
  return if YARD::Doctest.skips.any? { |skip| this.definition.include?(skip) }
28
28
 
29
- begin
30
- object_name = this.definition.split(/#|\./).first
31
- scope = Object.const_get(object_name) if const_defined?(object_name)
32
- rescue NameError
33
- end
34
-
35
29
  describe this.definition do
36
30
  # Append this.name to this.definition if YARD's @example tag is followed by
37
31
  # descriptive text, to support hooks for multiple examples per code object.
@@ -41,9 +35,15 @@ module YARD
41
35
  "#{this.definition}@#{this.name}"
42
36
  end
43
37
 
44
- register_hooks(example_name, YARD::Doctest.hooks)
38
+ register_hooks(example_name, YARD::Doctest.hooks, this)
45
39
 
46
40
  it this.name do
41
+ begin
42
+ object_name = this.definition.split(/#|\./).first
43
+ scope = Object.const_get(object_name) if self.class.const_defined?(object_name)
44
+ rescue NameError
45
+ end
46
+
47
47
  global_constants = Object.constants
48
48
  scope_constants = scope.constants if scope
49
49
  this.asserts.each do |assert|
@@ -140,12 +140,19 @@ module YARD
140
140
  end
141
141
  end
142
142
 
143
- def self.register_hooks(example_name, all_hooks)
144
- all_hooks.each do |type, hooks|
145
- global_hooks = hooks.select { |hook| !hook[:test] }
146
- test_hooks = hooks.select { |hook| hook[:test] && example_name.include?(hook[:test]) }
147
- __send__(type) do
148
- (global_hooks + test_hooks).each { |hook| instance_exec(&hook[:block]) }
143
+ class << self
144
+ protected
145
+
146
+ # @param [String] example_name The name of the example.
147
+ # @param [Hash<Symbol, Array<Hash<(test: String, block: Proc)>>] all_hooks
148
+ # @param [Example] example
149
+ def register_hooks(example_name, all_hooks, example)
150
+ all_hooks.each do |type, hooks|
151
+ global_hooks = hooks.reject { |hook| hook[:test] }
152
+ test_hooks = hooks.select { |hook| hook[:test] && example_name.include?(hook[:test]) }
153
+ __send__(type) do
154
+ (global_hooks + test_hooks).each { |hook| instance_exec(example, &hook[:block]) }
155
+ end
149
156
  end
150
157
  end
151
158
  end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module Doctest
3
- VERSION = '0.1.15'
3
+ VERSION = '0.1.16'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-doctest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-07 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard