yard-doctest 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/features/yard-doctest.feature +52 -2
- data/lib/yard/doctest/example.rb +24 -10
- data/lib/yard/doctest/version.rb +1 -1
- data/yard-doctest.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba9b291cde3beb389b61654c7c322867eda5c85
|
4
|
+
data.tar.gz: b0ed6bad33e7898a33aacbc1c297ef876da20bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3694a20bd31d53e3716d83a9f6062c958478b80f8f4e39ff26c5e32f5c911a5414dc4086230a66b46f654f2b5fa4af3dc4e1ebed56f2efbad446abb39749fa
|
7
|
+
data.tar.gz: f184b05173e542846f4b5d4c46907e1ed25b1edf80b82cf2831507758bdd3659ed3a06d7e91c244f76bccc0314bcaa2092c644b7cdb06d09378d0081beaf1307
|
data/CHANGELOG.md
CHANGED
@@ -597,7 +597,7 @@ Feature: yard doctest
|
|
597
597
|
|
598
598
|
class A
|
599
599
|
# @example
|
600
|
-
# A.foo
|
600
|
+
# A.foo #=> true
|
601
601
|
def self.foo
|
602
602
|
true
|
603
603
|
end
|
@@ -625,6 +625,27 @@ Feature: yard doctest
|
|
625
625
|
When I run `bundle exec yard doctest`
|
626
626
|
Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
|
627
627
|
|
628
|
+
Scenario: shares instance variables in local context binding
|
629
|
+
Given a file named "doctest_helper.rb" with:
|
630
|
+
"""
|
631
|
+
require 'app/app'
|
632
|
+
|
633
|
+
YARD::Doctest.before do
|
634
|
+
@flag = true
|
635
|
+
end
|
636
|
+
"""
|
637
|
+
And a file named "app/app.rb" with:
|
638
|
+
"""
|
639
|
+
class App
|
640
|
+
# @example
|
641
|
+
# @flag #=> true
|
642
|
+
def self.foo
|
643
|
+
end
|
644
|
+
end
|
645
|
+
"""
|
646
|
+
When I run `bundle exec yard doctest`
|
647
|
+
Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
|
648
|
+
|
628
649
|
Scenario: isolates constants per test
|
629
650
|
Given a file named "doctest_helper.rb" with:
|
630
651
|
"""
|
@@ -636,13 +657,42 @@ Feature: yard doctest
|
|
636
657
|
# ::FOO = 123
|
637
658
|
# ::FOO #=> 123
|
638
659
|
# ::BAR #=> raise NameError, 'uninitialized constant BAR'
|
660
|
+
# FOO = 456
|
661
|
+
# FOO #=> 456
|
662
|
+
# BAR #=> raise NameError, 'uninitialized constant App::BAR'
|
639
663
|
#
|
640
664
|
# @example
|
641
665
|
# ::BAR = 123
|
642
666
|
# ::BAR #=> 123
|
643
667
|
# ::FOO #=> raise NameError, 'uninitialized constant FOO'
|
668
|
+
# BAR = 123
|
669
|
+
# BAR #=> 123
|
670
|
+
# FOO #=> raise NameError, 'uninitialized constant App::FOO'
|
644
671
|
class App
|
645
672
|
end
|
646
673
|
"""
|
647
674
|
When I run `bundle exec yard doctest`
|
648
|
-
Then the output should contain "2 runs,
|
675
|
+
Then the output should contain "2 runs, 8 assertions, 0 failures, 0 errors, 0 skips"
|
676
|
+
|
677
|
+
Scenario: allows to run a single test
|
678
|
+
Given a file named "doctest_helper.rb" with:
|
679
|
+
"""
|
680
|
+
require 'app/app'
|
681
|
+
"""
|
682
|
+
And a file named "app/app.rb" with:
|
683
|
+
"""
|
684
|
+
class A
|
685
|
+
# @example First
|
686
|
+
# A.foo #=> true
|
687
|
+
#
|
688
|
+
# @example Second
|
689
|
+
# A.foo #=> false
|
690
|
+
def self.foo
|
691
|
+
true
|
692
|
+
end
|
693
|
+
end
|
694
|
+
"""
|
695
|
+
When I run `bundle exec yard doctest -v --name=/First/`
|
696
|
+
Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
|
697
|
+
When I run `bundle exec yard doctest -v --name=/Second/`
|
698
|
+
Then the output should contain "1 runs, 1 assertions, 1 failures, 0 errors, 0 skips"
|
data/lib/yard/doctest/example.rb
CHANGED
@@ -44,7 +44,8 @@ module YARD
|
|
44
44
|
register_hooks(example_name, YARD::Doctest.hooks)
|
45
45
|
|
46
46
|
it this.name do
|
47
|
-
|
47
|
+
global_constants = Object.constants
|
48
|
+
scope_constants = scope.constants if scope
|
48
49
|
this.asserts.each do |assert|
|
49
50
|
expected, actual = assert[:expected], assert[:actual]
|
50
51
|
if expected.empty?
|
@@ -53,7 +54,8 @@ module YARD
|
|
53
54
|
assert_example(this, expected, actual, scope)
|
54
55
|
end
|
55
56
|
end
|
56
|
-
clear_extra_constants(
|
57
|
+
clear_extra_constants(Object, global_constants)
|
58
|
+
clear_extra_constants(scope, scope_constants) if scope
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -83,13 +85,25 @@ module YARD
|
|
83
85
|
end
|
84
86
|
|
85
87
|
def evaluate(code, bind)
|
86
|
-
context.eval
|
87
|
-
rescue NameError
|
88
|
-
bind ? bind.__send__(:eval, code) : raise
|
88
|
+
context(bind).eval(code)
|
89
89
|
end
|
90
90
|
|
91
|
-
def context
|
92
|
-
@
|
91
|
+
def context(bind)
|
92
|
+
@context ||= begin
|
93
|
+
if bind
|
94
|
+
context = bind.class_eval('binding', __FILE__, __LINE__)
|
95
|
+
# Oh my god, what is happening here?
|
96
|
+
# We need to transplant instance variables from the current binding.
|
97
|
+
instance_variables.each do |instance_variable_name|
|
98
|
+
local_variable_name = "__yard_doctest__#{instance_variable_name.to_s.delete('@')}"
|
99
|
+
context.local_variable_set(local_variable_name, instance_variable_get(instance_variable_name))
|
100
|
+
context.eval("#{instance_variable_name} = #{local_variable_name}")
|
101
|
+
end
|
102
|
+
context
|
103
|
+
else
|
104
|
+
binding
|
105
|
+
end
|
106
|
+
end
|
93
107
|
end
|
94
108
|
|
95
109
|
def add_filepath_to_backtrace(exception, filepath)
|
@@ -100,9 +114,9 @@ module YARD
|
|
100
114
|
exception.set_backtrace backtrace
|
101
115
|
end
|
102
116
|
|
103
|
-
def clear_extra_constants(constants)
|
104
|
-
(
|
105
|
-
|
117
|
+
def clear_extra_constants(scope, constants)
|
118
|
+
(scope.constants - constants).each do |constant|
|
119
|
+
scope.__send__(:remove_const, constant)
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
data/lib/yard/doctest/version.rb
CHANGED
data/yard-doctest.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_runtime_dependency 'yard'
|
21
21
|
spec.add_runtime_dependency 'minitest'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
24
|
-
spec.add_development_dependency 'rake'
|
25
23
|
spec.add_development_dependency 'aruba'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'relish'
|
26
26
|
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.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rodionov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: relish
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.6.
|
124
|
+
rubygems_version: 2.6.14
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Doctests from YARD examples
|