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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e060a6fdecfeb740798431f7a26212efb2565771
4
- data.tar.gz: 3f4c8f9c7a9ab960a26e3b10dba993cb6c5bbb5c
3
+ metadata.gz: eba9b291cde3beb389b61654c7c322867eda5c85
4
+ data.tar.gz: b0ed6bad33e7898a33aacbc1c297ef876da20bcf
5
5
  SHA512:
6
- metadata.gz: aaee894607b41aa9a01378fe6b1eeda09058512a37a6687180a96788c3e0f204863c0afd1c34929f0c09e3dd3f322d6c44eecf7dc29491ddfa45a5c86b06a977
7
- data.tar.gz: dd6f612d02bdddd778cc8bb4315dca7e4928149697a8331ed0106a1f81ec0d8d52ea8b8130eb9aa1a6e8cbf918f600e3ec88d9e7a32ed8a5059cfa3c864aba45
6
+ metadata.gz: 9c3694a20bd31d53e3716d83a9f6062c958478b80f8f4e39ff26c5e32f5c911a5414dc4086230a66b46f654f2b5fa4af3dc4e1ebed56f2efbad446abb39749fa
7
+ data.tar.gz: f184b05173e542846f4b5d4c46907e1ed25b1edf80b82cf2831507758bdd3659ed3a06d7e91c244f76bccc0314bcaa2092c644b7cdb06d09378d0081beaf1307
@@ -1,3 +1,7 @@
1
+ ## 0.1.12
2
+
3
+ * Reworked the construction of context where examples are evaluated.
4
+
1
5
  ## 0.1.11
2
6
 
3
7
  * Remove constants defined during test execution for better isolation.
@@ -597,7 +597,7 @@ Feature: yard doctest
597
597
 
598
598
  class A
599
599
  # @example
600
- # A.foo => true
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, 4 assertions, 0 failures, 0 errors, 0 skips"
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"
@@ -44,7 +44,8 @@ module YARD
44
44
  register_hooks(example_name, YARD::Doctest.hooks)
45
45
 
46
46
  it this.name do
47
- constants = Object.constants
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(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 code
87
- rescue NameError
88
- bind ? bind.__send__(:eval, code) : raise
88
+ context(bind).eval(code)
89
89
  end
90
90
 
91
- def context
92
- @binding ||= binding
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
- (Object.constants - constants).each do |constant|
105
- Object.__send__(:remove_const, constant)
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
 
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module Doctest
3
- VERSION = '0.1.11'
3
+ VERSION = '0.1.12'
4
4
  end
5
5
  end
@@ -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.11
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-02-01 00:00:00.000000000 Z
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: bundler
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: aruba
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.13
124
+ rubygems_version: 2.6.14
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Doctests from YARD examples