yard-doctest 0.1.8 → 0.1.9

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
  SHA1:
3
- metadata.gz: 0cd1fc903edfa86337db79cf3b40f762fbf2cadc
4
- data.tar.gz: 408b814a356c164e4d894f1c9320ce422ffb8706
3
+ metadata.gz: 47ff35130e3241348736458652887da1bca96512
4
+ data.tar.gz: 76d18f3e48943bab0d1058082291d98fc3167477
5
5
  SHA512:
6
- metadata.gz: 0fba50d53837f55aef654d3e675ff8b3bca2128668f2599db051c0f4e0c1d11c4c9a1bb1b6d1b7fa697eff0c930675aea6f0e885336a70dc6db3cfc6db64e508
7
- data.tar.gz: c1b06e9a0119434cc69a5212a7d06982e69adfa2d1e025513299fc50646c5158a81d209341237ec3945c774386616c0a88089ab0d2d90dee2bd4d07c6c0b8744
6
+ metadata.gz: 00f1a7d01a6f625d858f275e6356f223d7af8487fe4faaafdd36f1e98fcd4193f8b20754ee332196a9df8878f1005cf269ef41ca634dbf16bba53437517a4711
7
+ data.tar.gz: 4f29c14960eb13d008ae1ef5ab97dbe763441c7d38b6bfee8064c529d160083d832f3b78c8548e0fc329773ab88eae0efee6e984c908d3c10960fcbf29c05845
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.9
2
+
3
+ * Allow to have `doctest_helper.rb` in `spec/` directory [#4](https://github.com/p0deje/yard-doctest/pull/4)
4
+ * Allow to use local context in doctest (i.e. not type full path to object) [#5](https://github.com/p0deje/yard-doctest/pull/5)
5
+
1
6
  ## 0.1.8
2
7
 
3
8
  * Fixed a bug when test was passing even though exception was raised in example
data/README.md CHANGED
@@ -99,8 +99,7 @@ Next, you'll need to create test helper, which will be required before each of y
99
99
 
100
100
  ```bash
101
101
  $ touch doctest_helper.rb
102
- # or if you don't want to have it in root
103
- $ touch support/doctest_helper.rb
102
+ # or move it into either the `support` or `spec` directory
104
103
  ```
105
104
 
106
105
  ```ruby
@@ -425,6 +425,7 @@ Feature: yard doctest
425
425
  | directory |
426
426
  | . |
427
427
  | support |
428
+ | spec |
428
429
 
429
430
  Scenario: shares binding between asserts
430
431
  Given a file named "doctest_helper.rb" with:
@@ -595,3 +596,22 @@ Feature: yard doctest
595
596
  """
596
597
  When I run `bundle exec yard doctest`
597
598
  Then the output should contain "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips"
599
+
600
+ Scenario: allow binding to local context
601
+ Given a file named "doctest_helper.rb" with:
602
+ """
603
+ require 'app/app'
604
+ """
605
+ And a file named "app/app.rb" with:
606
+ """
607
+ class App
608
+ # @example
609
+ # a, b = 1, 2
610
+ # sum(a, b) #=> 3
611
+ def self.sum(one, two)
612
+ one + two
613
+ end
614
+ end
615
+ """
616
+ When I run `bundle exec yard doctest`
617
+ Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
@@ -20,11 +20,18 @@ module YARD
20
20
  Class.new(this.class).class_eval do
21
21
  require 'minitest/autorun'
22
22
 
23
- %w[. support].each do |dir|
23
+ %w[. support spec].each do |dir|
24
24
  require "#{dir}/doctest_helper" if File.exist?("#{dir}/doctest_helper.rb")
25
25
  end
26
26
 
27
27
  return if YARD::Doctest.skips.any? { |skip| this.definition.include?(skip) }
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
+
28
35
  describe this.definition do
29
36
  # Append this.name to this.definition if YARD's @example tag is followed by
30
37
  # descriptive text, to support hooks for multiple examples per code object.
@@ -40,9 +47,9 @@ module YARD
40
47
  this.asserts.each do |assert|
41
48
  expected, actual = assert[:expected], assert[:actual]
42
49
  if expected.empty?
43
- evaluate_example(this, actual)
50
+ evaluate_example(this, actual, scope)
44
51
  else
45
- assert_example(this, expected, actual)
52
+ assert_example(this, expected, actual, scope)
46
53
  end
47
54
  end
48
55
  end
@@ -52,22 +59,22 @@ module YARD
52
59
 
53
60
  protected
54
61
 
55
- def evaluate_example(example, actual)
56
- context.eval(actual)
62
+ def evaluate_example(example, actual, bind)
63
+ (bind || context).send(:eval, actual)
57
64
  rescue StandardError => error
58
65
  add_filepath_to_backtrace(error, example.filepath)
59
66
  raise error
60
67
  end
61
68
 
62
- def assert_example(example, expected, actual)
63
- assert_equal evaluate(expected), evaluate(actual)
69
+ def assert_example(example, expected, actual, bind)
70
+ assert_equal evaluate(expected, bind), evaluate(actual, bind)
64
71
  rescue Minitest::Assertion => error
65
72
  add_filepath_to_backtrace(error, example.filepath)
66
73
  raise error
67
74
  end
68
75
 
69
- def evaluate(code)
70
- context.eval(code)
76
+ def evaluate(code, bind)
77
+ (bind || context).send(:eval, code)
71
78
  rescue StandardError => error
72
79
  "#<#{error.class}: #{error}>"
73
80
  end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module Doctest
3
- VERSION = '0.1.8'
3
+ VERSION = '0.1.9'
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-30 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -121,11 +121,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.4.5.1
124
+ rubygems_version: 2.5.2
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Doctests from YARD examples
128
128
  test_files:
129
129
  - features/support/env.rb
130
130
  - features/yard-doctest.feature
131
- has_rdoc: