yard-doctest 0.1.14 → 0.1.15

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
  SHA256:
3
- metadata.gz: 4952a0dc4b12093ceb7ae21eae44e735412b0c7e5b17e1b71d435f2fbbdce964
4
- data.tar.gz: 6b583b324be15b5519435a021293691a3266ce039789928c19bcb59d4a67d4e0
3
+ metadata.gz: 723dea9f19d8563896620983b07e9c10c8ffd675fec6c630265dd1b7c9296137
4
+ data.tar.gz: fe76d9dee40e4ced8ceaea99cc0b6e985e9dc347e6b74dc373f6d568e8c00bb8
5
5
  SHA512:
6
- metadata.gz: 0560d34f0aeaa28034eaa640e0319539098a1848820696044a1cf805f5f77aeca07206d94394cc74b1dc75a1a3f375cb60d91e51c8d623b200dc33d0a2279b4d
7
- data.tar.gz: 1092ec6db552c0355bdf7765df7581b6d29ec555ad33143b5a150721f1830083703f823d6f13e8157ec4c4fd5768ee702b7a00b7dcb89551a90724a39262c474
6
+ metadata.gz: 222ad5b8623b913c3c16dd7ea76731e9b2b889285f3221c242de8ade6cf55870b09d541d71a9e239611867737306a06f75994f51cc5f39c77cd0c504ff512431
7
+ data.tar.gz: 1715dab13e1e08605bda7ed64c61a978c8c6230745470beddd78bba79b8a2f970577d667980b65c4c64109e426e45986efc201387c3a73b6a2525a0a1900088f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.15
2
+
3
+ * Fix an issue when exception is swallowed in assertion phase
4
+
1
5
  ## 0.1.14
2
6
 
3
7
  * Allow to use without Rake installed. If you want to use Rake task, please add
@@ -5,7 +5,7 @@ Feature: yard doctest
5
5
  I want to automatically parse YARD's @example tags
6
6
  And use them as tests
7
7
  Just like doctest in Python
8
-
8
+
9
9
  Background:
10
10
  # YARD stopped auto-loading all plugins at 0.6.2, so anything newer needs
11
11
  # the plugin explicitly loaded. A simple way to do this is to always have
@@ -138,6 +138,10 @@ Feature: yard doctest
138
138
  #foo#test_0001_:
139
139
  RuntimeError: Fails with exception
140
140
  """
141
+ And the output should contain:
142
+ """
143
+ app/app.rb:4:in `foo'
144
+ """
141
145
 
142
146
  Scenario: asserts using equality
143
147
  Given a file named "doctest_helper.rb" with:
@@ -735,3 +739,29 @@ Feature: yard doctest
735
739
  """
736
740
  When I run `bundle exec yard doctest`
737
741
  Then the output should contain "1 runs, 0 assertions, 0 failures, 0 errors, 0 skips"
742
+
743
+ Scenario: shows exception when assert raises one
744
+ Given a file named "doctest_helper.rb" with:
745
+ """
746
+ require 'app/app'
747
+ """
748
+ And a file named "app/app.rb" with:
749
+ """
750
+ # @example
751
+ # foo #=> 1
752
+ def foo
753
+ raise 'Fails with exception'
754
+ end
755
+ """
756
+ When I run `bundle exec yard doctest`
757
+ Then the exit status should be 1
758
+ And the output should contain:
759
+ """
760
+ 1) Error:
761
+ #foo#test_0001_:
762
+ RuntimeError: Fails with exception
763
+ """
764
+ And the output should contain:
765
+ """
766
+ app/app.rb:4:in `foo'
767
+ """
@@ -71,8 +71,16 @@ module YARD
71
71
  end
72
72
 
73
73
  def assert_example(example, expected, actual, bind)
74
- assert_equal(evaluate_with_assertion(expected, bind),
75
- evaluate_with_assertion(actual, bind))
74
+ expected = evaluate_with_assertion(expected, bind)
75
+ actual = evaluate_with_assertion(actual, bind)
76
+
77
+ if both_are_errors?(expected, actual)
78
+ assert_equal("#<#{expected.class}: #{expected}>", "#<#{actual.class}: #{actual}>")
79
+ elsif (error = only_one_is_error?(expected, actual))
80
+ raise error
81
+ else
82
+ assert_equal(expected, actual)
83
+ end
76
84
  rescue Minitest::Assertion => error
77
85
  add_filepath_to_backtrace(error, example.filepath)
78
86
  raise error
@@ -81,7 +89,7 @@ module YARD
81
89
  def evaluate_with_assertion(code, bind)
82
90
  evaluate(code, bind)
83
91
  rescue StandardError => error
84
- "#<#{error.class}: #{error}>"
92
+ error
85
93
  end
86
94
 
87
95
  def evaluate(code, bind)
@@ -106,6 +114,18 @@ module YARD
106
114
  end
107
115
  end
108
116
 
117
+ def both_are_errors?(expected, actual)
118
+ expected.is_a?(StandardError) && actual.is_a?(StandardError)
119
+ end
120
+
121
+ def only_one_is_error?(expected, actual)
122
+ if expected.is_a?(StandardError) && !actual.is_a?(StandardError)
123
+ expected
124
+ elsif !expected.is_a?(StandardError) && actual.is_a?(StandardError)
125
+ actual
126
+ end
127
+ end
128
+
109
129
  def add_filepath_to_backtrace(exception, filepath)
110
130
  backtrace = exception.backtrace
111
131
  line = backtrace.find { |l| l =~ %r{lib/yard/doctest/example} }
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module Doctest
3
- VERSION = '0.1.14'
3
+ VERSION = '0.1.15'
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.14
4
+ version: 0.1.15
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-04 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.6
123
+ rubygems_version: 3.0.1
125
124
  signing_key:
126
125
  specification_version: 4
127
126
  summary: Doctests from YARD examples