yard-doctest 0.1.4 → 0.1.5

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: d05d9acd352595e01d0810a9b5a28c5f765339a9
4
- data.tar.gz: 39de91d11961df2ae8ac5825d35adb973ad885ab
3
+ metadata.gz: 216ca29f83eef3428bc20ff8a2ca765b605e8428
4
+ data.tar.gz: 4c821cbbd5d8c861c365fb57d6defa9f99726002
5
5
  SHA512:
6
- metadata.gz: 876ea8d1f88bbb88b7c3cc2ec06318985122d86a5fb96f36f66c08cb47c74073e55a1e0dd287b7a1414b85f7d1b9a5985fe4374a622cc4942157551b1906fb75
7
- data.tar.gz: dd9b9c3afea9b45560a421b2d9ad15563db3c510e33e90fc18df6d21601847e2a23c2af8d6b1db70f10c319decdf46002207ad5223c173f5c557bf7904ab3ebb
6
+ metadata.gz: 831c02685ac564f579baeb4ecde9d6994e7ee09a34db02556bcac5f3ee799eda2c816905a524a659602d1316b5a3bc4c9b18a0a89f1502add3a9dce86e2a11db
7
+ data.tar.gz: 360322c342fb9d2b567c8d250968a3087b5a7f4ee2e5a4270ce2ee6de6161d8ad0fce80fb37557e502376ca9a9ca92884666bf9e4b6f6a628315118d8028f8d4
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
3
  - 2.1.0
5
4
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Alex Rodionov
1
+ Copyright (c) 2015 Alex Rodionov
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # yard-doctest [![Gem Version](https://badge.fury.io/rb/yard-doctest.png)](http://badge.fury.io/rb/yard-doctest) [![Build Status](https://travis-ci.org/p0deje/yard-doctest.png?branch=master)](https://travis-ci.org/p0deje/yard-doctest)
1
+ # yard-doctest [![Gem Version](https://badge.fury.io/rb/yard-doctest.svg)](http://badge.fury.io/rb/yard-doctest) [![Build Status](https://travis-ci.org/p0deje/yard-doctest.png?branch=master)](https://travis-ci.org/p0deje/yard-doctest)
2
2
 
3
3
  Have you ever wanted to turn your amazing code examples into something that really make sense, is always up-to-date and bullet-proof? Were looking at an amazing [Python doctest](https://docs.python.org/3/library/doctest.html)? Well, look no longer!
4
4
 
@@ -99,6 +99,8 @@ 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
104
  ```
103
105
 
104
106
  ```ruby
@@ -195,6 +197,22 @@ It is actually delegated to amazing [minitest](https://github.com/seattlerb/mini
195
197
 
196
198
  ## Advanced usage
197
199
 
200
+ ### Exceptions
201
+
202
+ If you want to use example that raises exception, this can be achieved by specifying the correct expected value:
203
+
204
+ ```ruby
205
+ class Calculator
206
+ # @example
207
+ # divide(1, 0) #=> raise ZeroDivisionError, "divided by 0"
208
+ def divide(one, two)
209
+ one / two
210
+ end
211
+ end
212
+ ```
213
+
214
+ The comparison of raised exceptions is being done by string containing the class and message of exceptions. With that said, you have to use the same message in expected value as the one that is used in actual.
215
+
198
216
  ### Test helper
199
217
 
200
218
  You can define any methods and instance variables in test helper and they will be available in examples.
@@ -302,6 +320,10 @@ end
302
320
  $ bundle exec rake yard:doctest
303
321
  ```
304
322
 
323
+ ## Is it really used?
324
+
325
+ Well, yeah. A great example of using yard-doctest is [watir-webdriver](https://github.com/watir/watir-webdriver).
326
+
305
327
  ## Testing
306
328
 
307
329
  There are some system tests implemented with [Aruba](https://github.com/cucumber/aruba):
@@ -128,6 +128,22 @@ Feature: yard doctest
128
128
  Actual: "2"
129
129
  """
130
130
 
131
+ Scenario: asserts exceptions
132
+ Given a file named "doctest_helper.rb" with:
133
+ """
134
+ require 'app/app'
135
+ """
136
+ And a file named "app/app.rb" with:
137
+ """
138
+ # @example
139
+ # divide(1, 0) #=> raise ZeroDivisionError, "divided by 0"
140
+ def divide(one, two)
141
+ one / two
142
+ end
143
+ """
144
+ When I run `bundle exec yard doctest`
145
+ Then the output should contain "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips"
146
+
131
147
  Scenario Outline: properly handles different return values
132
148
  Given a file named "doctest_helper.rb" with:
133
149
  """
@@ -428,9 +444,11 @@ Feature: yard doctest
428
444
  """
429
445
  require 'app/app'
430
446
 
431
- YARD::Doctest.before { @flag = false }
432
- YARD::Doctest.after { @flag = true }
433
- YARD::Doctest.after_run { puts 'Run after all by minitest' }
447
+ YARD::Doctest.configure do |doctest|
448
+ doctest.before { @flag = false }
449
+ doctest.after { @flag = true }
450
+ doctest.after_run { puts 'Run after all by minitest' }
451
+ end
434
452
  """
435
453
  And a file named "app/app.rb" with:
436
454
  """
@@ -1,5 +1,3 @@
1
- require 'sourcify'
2
-
3
1
  module YARD
4
2
  module Doctest
5
3
  class Example < ::Minitest::Spec
@@ -21,29 +19,25 @@ module YARD
21
19
 
22
20
  Class.new(this.class).class_eval do
23
21
  require 'minitest/autorun'
24
- if File.exists?('doctest_helper.rb')
25
- require 'doctest_helper'
26
- elsif File.exists?('support/doctest_helper.rb')
27
- require 'support/doctest_helper'
22
+
23
+ %w[. support].each do |dir|
24
+ require "#{dir}/doctest_helper" if File.exist?("#{dir}/doctest_helper.rb")
28
25
  end
29
26
 
30
- unless YARD::Doctest.skips.any? { |skip| this.definition.include?(skip) }
31
- describe this.definition do
32
- register_hooks(this.definition, YARD::Doctest.hooks)
27
+ return if YARD::Doctest.skips.any? { |skip| this.definition.include?(skip) }
28
+ describe this.definition do
29
+ register_hooks(this.definition, YARD::Doctest.hooks)
33
30
 
34
- it this.name do
35
- this.asserts.each do |assert|
36
- expected, actual = assert[:expected], assert[:actual]
37
- actual = context.eval(actual)
31
+ it this.name do
32
+ this.asserts.each do |assert|
33
+ expected, actual = assert[:expected], assert[:actual]
34
+ next if expected.empty?
38
35
 
39
- unless expected.empty?
40
- begin
41
- assert_equal evaluate(expected), actual
42
- rescue Minitest::Assertion => error
43
- add_filepath_to_backtrace(error, this.filepath)
44
- raise error
45
- end
46
- end
36
+ begin
37
+ assert_equal evaluate(expected), evaluate(actual)
38
+ rescue Minitest::Assertion => error
39
+ add_filepath_to_backtrace(error, this.filepath)
40
+ raise error
47
41
  end
48
42
  end
49
43
  end
@@ -54,8 +48,9 @@ module YARD
54
48
  protected
55
49
 
56
50
  def evaluate(code)
57
- code = code.to_source(strip_enclosure: true) if code.is_a?(Proc)
58
51
  context.eval(code)
52
+ rescue StandardError => error
53
+ "#<#{error.class}: #{error}>"
59
54
  end
60
55
 
61
56
  def context
@@ -64,7 +59,7 @@ module YARD
64
59
 
65
60
  def add_filepath_to_backtrace(exception, filepath)
66
61
  backtrace = exception.backtrace
67
- line = backtrace.find { |l| l =~ %r(lib/yard/doctest/example) }
62
+ line = backtrace.find { |l| l =~ %r{lib/yard/doctest/example} }
68
63
  index = backtrace.index(line)
69
64
  backtrace = backtrace.insert(index, filepath)
70
65
  exception.set_backtrace backtrace
@@ -75,12 +70,10 @@ module YARD
75
70
  hooks.each do |hook|
76
71
  if hook[:test]
77
72
  # test-name hooks
78
- if definition.include?(hook[:test])
79
- send(type) { evaluate(hook[:block]) }
80
- end
73
+ send(type, &hook[:block]) if definition.include?(hook[:test])
81
74
  else
82
75
  # global hooks
83
- send(type) { evaluate(hook[:block]) }
76
+ send(type, &hook[:block])
84
77
  end
85
78
  end
86
79
  end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module Doctest
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
data/lib/yard-doctest.rb CHANGED
@@ -30,7 +30,7 @@ module YARD
30
30
  # @param [Proc] blk
31
31
  #
32
32
  def before(test = nil, &blk)
33
- hooks[:before] << {test: test, block: blk} if block_given?
33
+ hooks[:before] << {test: test, block: blk}
34
34
  end
35
35
 
36
36
  #
@@ -43,7 +43,7 @@ module YARD
43
43
  # @param [Proc] blk
44
44
  #
45
45
  def after(test = nil, &blk)
46
- hooks[:after] << {test: test, block: blk} if block_given?
46
+ hooks[:after] << {test: test, block: blk}
47
47
  end
48
48
 
49
49
  #
data/yard-doctest.gemspec CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency 'yard'
21
21
  spec.add_runtime_dependency 'minitest'
22
- spec.add_runtime_dependency 'sourcify'
23
22
 
24
23
  spec.add_development_dependency 'bundler'
25
24
  spec.add_development_dependency 'rake'
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: sourcify
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement