yard-rspec_examples 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +3 -0
- data/Gemfile +9 -1
- data/README.md +84 -0
- data/Rakefile +3 -14
- data/lib/yard-rspec_examples.rb +2 -29
- data/lib/yard/rspec_examples/describe_handler.rb +3 -20
- data/lib/yard/rspec_examples/it_handler.rb +9 -4
- data/lib/yard/rspec_examples/module_handler.rb +2 -22
- data/lib/yard/rspec_examples/parser_trace.rb +19 -2
- data/lib/yard/rspec_examples/version.rb +1 -1
- data/lib/yard/tags/rspec_example_tag.rb +51 -0
- data/spec/fixtures/example_file.rb +9 -0
- data/spec/inline_examples_spec.rb +24 -0
- data/spec/named_examples_spec.rb +27 -0
- data/spec/nested_class_spec.rb +48 -0
- data/spec/nested_modules_spec.rb +59 -0
- data/spec/simple_context_spec.rb +26 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/yard-rspec_examples_spec.rb +34 -25
- metadata +15 -4
- data/README.rdoc +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 622d647f404d59aeee33f91d2b98666bab13fb8e
|
4
|
+
data.tar.gz: bbfb8cdead28af1b2139fafa6d3b7608fc74e961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11b660458e260e6f92a5a6f975f7bbb77b1da4e3e4e3c97e5d8dc7bb7fab4b9ac784a81c07a3f5a7139bcbc310b265679c57c241eac8ad23a24a6cd2a66a404d
|
7
|
+
data.tar.gz: 3877e218e518686565f7b0c405701b3aa21095b76eba397be8c262892e12c83ce8356e6d6d4ee2853c843cb0f5788eef93f318ff5e482a3f98e3439a42ace6b4
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
[![Build Status](http://img.shields.io/travis/UP-nxt/yard-rspec_examples.svg)](https://travis-ci.org/UP-nxt/yard-rspec_examples)
|
2
|
+
[![Dependency Status](https://img.shields.io/gemnasium/UP-nxt/yard-rspec_examples.svg)](https://gemnasium.com/UP-nxt/yard-rspec_examples)
|
3
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/UP-nxt/yard-rspec_examples.svg)](https://codeclimate.com/UP-nxt/yard-rspec_examples)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/UP-nxt/yard-rspec_examples/badge.svg?branch=master&service=github)](https://coveralls.io/github/UP-nxt/yard-rspec_examples?branch=master)
|
5
|
+
|
6
|
+
|
7
|
+
# yard-rspec_examples
|
8
|
+
|
9
|
+
Yard plugin to include examples in the generated doc through rspec
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
In order to install it you just have to install it gem from gemcutter
|
14
|
+
|
15
|
+
gem install yard-rspec_examples
|
16
|
+
|
17
|
+
## Description
|
18
|
+
|
19
|
+
This plugin simply includes an example tag and recreates it with the source code that corresponds
|
20
|
+
to the first example included in the describe blocks below.
|
21
|
+
This have to be defined inside a describe block called "#method_name" that, in turn,
|
22
|
+
has to be defined in a describe block with the class name, i.e. the regular way people use rspec when testing objects.
|
23
|
+
|
24
|
+
So, for example,
|
25
|
+
|
26
|
+
Given this source code:
|
27
|
+
|
28
|
+
class Foo
|
29
|
+
##
|
30
|
+
# This is a foo method with an example
|
31
|
+
# @rspec_example
|
32
|
+
def foo_method
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
And this spec:
|
37
|
+
|
38
|
+
describe Foo do
|
39
|
+
describe "#foo_method" do
|
40
|
+
it "works this way" do
|
41
|
+
this = "is"
|
42
|
+
# The code that will be included in the example
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
A result like this is to be expected
|
48
|
+
|
49
|
+
class Foo
|
50
|
+
##
|
51
|
+
# This is a foo method with an example
|
52
|
+
# @example
|
53
|
+
# this = "is"
|
54
|
+
# # The code that will be included in the example
|
55
|
+
def foo_method
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Another usage is to pass the example's name to the tag, using the regular conventions for rspec descriptions as they
|
60
|
+
are used with the ```--example``` option of the rspec executable.
|
61
|
+
|
62
|
+
@rspec_example #foo_method works this way
|
63
|
+
class Foo
|
64
|
+
##
|
65
|
+
# This is a foo method with an example
|
66
|
+
# @rspec_example works this way
|
67
|
+
def foo_method
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@rspec_example Foo#foo_method works this way
|
72
|
+
class AnotherClass
|
73
|
+
end
|
74
|
+
|
75
|
+
## Using it
|
76
|
+
|
77
|
+
In order to use it, you just have to add the --plugin param plus yours
|
78
|
+
|
79
|
+
yardoc --plugin yar-rspec_examples [OPTS]
|
80
|
+
|
81
|
+
|
82
|
+
## Copyright
|
83
|
+
Copyright partly(c) 2011 Jose Fernandez (magec).
|
84
|
+
See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
|
8
|
-
Bundler::GemHelper.install_tasks
|
9
|
-
|
10
1
|
require 'rspec/core/rake_task'
|
11
2
|
|
12
|
-
RSpec::Core::RakeTask.new(:spec) do |
|
13
|
-
|
3
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
4
|
+
spec.rspec_opts = ['--options', 'spec/rspec.opts']
|
14
5
|
end
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
require 'rake'
|
7
|
+
task default: [:spec]
|
data/lib/yard-rspec_examples.rb
CHANGED
@@ -4,6 +4,7 @@ require 'yard/rspec_examples/it_handler'
|
|
4
4
|
require 'yard/rspec_examples/module_handler'
|
5
5
|
require 'yard/rspec_examples/describe_handler'
|
6
6
|
require 'yard/rspec_examples/parser_trace'
|
7
|
+
require 'yard/tags/rspec_example_tag'
|
7
8
|
|
8
9
|
##
|
9
10
|
# This class will hold a map that associates the method descriptions with its source code
|
@@ -15,36 +16,8 @@ end
|
|
15
16
|
|
16
17
|
module YARD
|
17
18
|
module Tags
|
18
|
-
##
|
19
|
-
# A new type of tags has to be used cause we need to intercept the
|
20
|
-
# text call and generate its contents (in generation time, after everything was parsed)
|
21
|
-
class RSpecExampleTag < Tag
|
22
|
-
def text
|
23
|
-
# for now, we just handle case where describes are derived from the context
|
24
|
-
example_description = rspec_description(object).gsub(/^::/,'').gsub(/ ::/, ' ')
|
25
|
-
example_description += " #{name}" unless name.empty?
|
26
|
-
key = RSpecExampleRegistry.example_map.keys.detect{|k| k.include?(example_description)}
|
27
|
-
puts "[warn] Could not find example '#{example_description}'" unless key
|
28
|
-
@text = RSpecExampleRegistry.example_map[key]
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def rspec_description(object)
|
33
|
-
case object
|
34
|
-
when CodeObjects::RootObject
|
35
|
-
""
|
36
|
-
when CodeObjects::MethodObject
|
37
|
-
"#{rspec_description(object.namespace)} ##{object.name}"
|
38
|
-
when CodeObjects::ClassObject
|
39
|
-
"#{rspec_description(object.namespace)}::#{object.name}"
|
40
|
-
when CodeObjects::ModuleObject
|
41
|
-
"#{rspec_description(object.namespace)}#{object.name} "
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
19
|
class DefaultFactory
|
47
|
-
def parse_tag_with_rspec_example_tag(
|
20
|
+
def parse_tag_with_rspec_example_tag(_, text)
|
48
21
|
RSpecExampleTag.new(:example, "", [], text)
|
49
22
|
end
|
50
23
|
end
|
@@ -5,30 +5,13 @@ module YARD
|
|
5
5
|
class RSpecDescribeHandler < YARD::Handlers::Ruby::Base
|
6
6
|
|
7
7
|
handles method_call(:describe)
|
8
|
+
handles method_call(:context)
|
8
9
|
|
9
10
|
def process
|
10
11
|
param = statement.parameters.first
|
11
|
-
|
12
|
-
subject = nil
|
13
|
-
|
14
|
-
# A class is being declared
|
15
|
-
if param.type == :var_ref && param.children.first.type == :const
|
16
|
-
subject = param.children.first.source
|
17
|
-
end
|
18
|
-
|
19
|
-
# A class is being declared (with a nested name)
|
20
|
-
if param.type == :const_path_ref
|
21
|
-
subject = param.children.map { |i| i.source }.join("::")
|
22
|
-
end
|
23
|
-
|
24
|
-
# A method is being declared
|
25
|
-
if param.type == :string_literal && param.source =~ /^"#/
|
26
|
-
subject = param.source.delete('"|\ ')
|
27
|
-
end
|
28
|
-
|
29
|
-
ParserTrace.path.push(subject.dup) if subject
|
12
|
+
ParserTrace.stack.push(param)
|
30
13
|
parse_block(statement.last.last)
|
31
|
-
ParserTrace.
|
14
|
+
ParserTrace.stack.pop
|
32
15
|
end
|
33
16
|
end
|
34
17
|
end
|
@@ -6,10 +6,15 @@ module YARD
|
|
6
6
|
handles method_call(:it)
|
7
7
|
|
8
8
|
def process
|
9
|
-
it_description = statement.parameters.source[1...-1]
|
10
|
-
rspec_path_string =
|
11
|
-
|
12
|
-
|
9
|
+
it_description = statement.parameters.empty? ? '' : statement.parameters.source[1...-1]
|
10
|
+
rspec_path_string = full_example_description(it_description)
|
11
|
+
RSpecExampleRegistry.example_map[rspec_path_string] = statement.block.source.gsub(/\A\s*do\s*^(.*)end\s*\z/m, '\\1')
|
12
|
+
.gsub(/\Ado;\s*(.*)\s*end\z/m, '\\1')
|
13
|
+
.gsub(/\A{\s*(.*)\s*}/m, '\\1').rstrip
|
14
|
+
end
|
15
|
+
|
16
|
+
def full_example_description(it_description)
|
17
|
+
"#{ParserTrace.full_description} #{it_description}"
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
@@ -4,29 +4,9 @@ module YARD
|
|
4
4
|
handles :module
|
5
5
|
|
6
6
|
def process
|
7
|
-
|
8
|
-
#
|
9
|
-
# subject = nil
|
10
|
-
#
|
11
|
-
# # A class is being declared
|
12
|
-
# if param.type == :var_ref && param.children.first.type == :const
|
13
|
-
# subject = param.children.first.source
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# # A class is being declared (with a nested name)
|
17
|
-
# if param.type == :const_path_ref
|
18
|
-
# subject = param.children.map { |i| i.source }.join("::")
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# # A method is being declared
|
22
|
-
# if param.type == :string_literal && param.source =~ /^"#/
|
23
|
-
# subject = param.source.delete('"|\ ')
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
#TODO: probably thave to strip namespace from the module
|
27
|
-
ParserTrace.path.push(statement.module_name.path)
|
7
|
+
ParserTrace.stack.push(statement.first)
|
28
8
|
parse_block(statement.last.last)
|
29
|
-
ParserTrace.
|
9
|
+
ParserTrace.stack.pop
|
30
10
|
end
|
31
11
|
|
32
12
|
end
|
@@ -1,8 +1,25 @@
|
|
1
1
|
module YARD
|
2
2
|
module RSpecExamples
|
3
3
|
class ParserTrace
|
4
|
-
def self.
|
5
|
-
@
|
4
|
+
def self.stack
|
5
|
+
@stack ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.full_description
|
9
|
+
@stack.reverse.reduce("") do |result, o|
|
10
|
+
case o.type
|
11
|
+
when :string_literal
|
12
|
+
description = o.source[1..-2]
|
13
|
+
prefix = description =~ /^(#|\.|::)/ ? '' : ' '
|
14
|
+
prefix + description + result
|
15
|
+
when :var_ref
|
16
|
+
"::#{o.path.first}#{result}"
|
17
|
+
when :const_ref
|
18
|
+
"::#{o.path.first}#{result}"
|
19
|
+
else
|
20
|
+
o.source + result
|
21
|
+
end
|
22
|
+
end.gsub(/^::/, '')
|
6
23
|
end
|
7
24
|
end
|
8
25
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module YARD
|
2
|
+
module Tags
|
3
|
+
##
|
4
|
+
# A new type of tags has to be used cause we need to intercept the
|
5
|
+
# text call and generate its contents (in generation time, after everything was parsed)
|
6
|
+
class RSpecExampleTag < Tag
|
7
|
+
def text
|
8
|
+
# for now, we just handle case where describes are derived from the context
|
9
|
+
example_description = full_rspec_description
|
10
|
+
key = find_key(example_description, @name)
|
11
|
+
puts "[warn] Could not find example '#{example_description}'" unless key
|
12
|
+
@text = RSpecExampleRegistry.example_map[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
find_key(full_rspec_description, @name) || ''
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def find_key(example_description, name)
|
22
|
+
key = RSpecExampleRegistry.example_map.keys.detect { |k| k.include?(example_description) }
|
23
|
+
key || RSpecExampleRegistry.example_map.keys.detect { |k| k.include?(name) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def full_rspec_description
|
27
|
+
example_description = rspec_description(object).gsub(/^::/, '')
|
28
|
+
example_description + (@name.empty? ? '' : (@name.to_s =~ /^(#|\.)/ ? @name.to_s : " #{@name}"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def rspec_description(object)
|
32
|
+
case object
|
33
|
+
when CodeObjects::RootObject
|
34
|
+
""
|
35
|
+
when CodeObjects::MethodObject
|
36
|
+
if object.scope == :instance
|
37
|
+
"#{rspec_description(object.namespace)}##{object.name}"
|
38
|
+
else
|
39
|
+
"#{rspec_description(object.namespace)}.#{object.name}"
|
40
|
+
end
|
41
|
+
when CodeObjects::ClassObject
|
42
|
+
"::#{object.name}"
|
43
|
+
when CodeObjects::ModuleObject
|
44
|
+
"#{rspec_description(object.namespace)}::#{object.name}"
|
45
|
+
else
|
46
|
+
""
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,19 +1,28 @@
|
|
1
|
+
# @rspec_example #foo_method
|
2
|
+
# @rspec_example #foo_method also supports this
|
1
3
|
class Foo
|
2
4
|
##
|
3
5
|
# This is a foo method with an example
|
4
6
|
# @rspec_example
|
5
7
|
# @rspec_example also supports this
|
8
|
+
# @rspec_example supports single line do begin
|
9
|
+
# @rspec_example supports curly braces syntax
|
6
10
|
def foo_method
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
10
14
|
class Foo
|
15
|
+
# @rspec_example Bar#bar_method
|
11
16
|
class Bar
|
12
17
|
##
|
13
18
|
# This is a class nested example
|
14
19
|
# @rspec_example
|
15
20
|
def bar_method
|
16
21
|
end
|
22
|
+
|
23
|
+
# @rspec_example
|
24
|
+
def self.class_method
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Eggplant
|
4
|
+
# @rspec_example
|
5
|
+
def instance_method
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Eggplant do
|
10
|
+
subject { -> { Eggplant.new.instance_method } }
|
11
|
+
it { is_expected.not_to raise_error }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'rspec_examples' do
|
15
|
+
context 'with inline examples' do
|
16
|
+
before { YARD.parse(__FILE__) }
|
17
|
+
subject do
|
18
|
+
output = YARD::Registry.all(:class).find { |i| i.to_s == "Eggplant" }
|
19
|
+
output = YARD::Templates::Engine.render(OPTIONS.merge(:object => output))
|
20
|
+
Nokogiri.HTML(output).css('.examples .example').map(&:text)
|
21
|
+
end
|
22
|
+
it { is_expected.to include 'is_expected.not_to raise_error' }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class NamedExample
|
4
|
+
# @rspec_example can be executed
|
5
|
+
def a_method
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe NamedExample do
|
10
|
+
describe '#a_method' do
|
11
|
+
it 'can be executed' do
|
12
|
+
NamedExample.new.a_method
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe NamedExample do
|
18
|
+
subject do
|
19
|
+
-> {
|
20
|
+
YARD.parse(__FILE__)
|
21
|
+
output = YARD::Registry.all(:class).find { |i| i.to_s == 'NamedExample' }
|
22
|
+
YARD::Templates::Engine.render(OPTIONS.merge(:object => output))
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
it { is_expected.not_to output.to_stdout }
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# @rspec_example Beetroot#instance_method
|
4
|
+
# @rspec_example Beetroot.class_method
|
5
|
+
class Asparagus
|
6
|
+
# @rspec_example #instance_method
|
7
|
+
# @rspec_example .class_method
|
8
|
+
class Beetroot
|
9
|
+
# @rspec_example
|
10
|
+
def instance_method
|
11
|
+
end
|
12
|
+
|
13
|
+
# @rspec_example
|
14
|
+
def self.class_method
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @rspec_example Asparagus::Beetroot#instance_method
|
20
|
+
# @rspec_example Asparagus::Beetroot.class_method
|
21
|
+
class Zucchini
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Asparagus::Beetroot do
|
25
|
+
describe '#instance_method' do
|
26
|
+
it 'can be called' do
|
27
|
+
Asparagus::Beetroot.new.instance_method
|
28
|
+
end
|
29
|
+
end
|
30
|
+
describe '.class_method' do
|
31
|
+
it 'can be called' do
|
32
|
+
Asparagus::Beetroot.class_method
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'rspec_examples' do
|
38
|
+
context 'with nested classes' do
|
39
|
+
it "renders without warning" do
|
40
|
+
expect do
|
41
|
+
YARD.parse(__FILE__)
|
42
|
+
YARD::Registry.all.each do |o|
|
43
|
+
YARD::Templates::Engine.render(OPTIONS.merge(:object => o))
|
44
|
+
end
|
45
|
+
end.not_to output.to_stdout
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# @rspec_example NestedModule::EmbeddedClass#instance_method
|
4
|
+
# @rspec_example NestedModule::EmbeddedClass.class_method
|
5
|
+
module TopModule
|
6
|
+
# @rspec_example EmbeddedClass#instance_method
|
7
|
+
# @rspec_example EmbeddedClass.class_method
|
8
|
+
module NestedModule
|
9
|
+
# @rspec_example #instance_method
|
10
|
+
# @rspec_example .class_method
|
11
|
+
class EmbeddedClass
|
12
|
+
# @rspec_example
|
13
|
+
def instance_method
|
14
|
+
end
|
15
|
+
|
16
|
+
# @rspec_example
|
17
|
+
def self.class_method
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @rspec_example TopModule::NestedModule::EmbeddedClass#instance_method
|
24
|
+
# @rspec_example TopModule::NestedModule::EmbeddedClass.class_method
|
25
|
+
class AnotherClass
|
26
|
+
end
|
27
|
+
|
28
|
+
module TopModule
|
29
|
+
module NestedModule
|
30
|
+
describe EmbeddedClass do
|
31
|
+
describe '#instance_method' do
|
32
|
+
it 'can be called' do
|
33
|
+
EmbeddedClass.new.instance_method
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe '.class_method' do
|
37
|
+
it 'can be called' do
|
38
|
+
EmbeddedClass.class_method
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module TopModule
|
46
|
+
module NestedModule
|
47
|
+
describe EmbeddedClass do
|
48
|
+
it "renders without warning" do
|
49
|
+
expect do
|
50
|
+
YARD.parse(__FILE__)
|
51
|
+
YARD::Registry.all.each do |o|
|
52
|
+
YARD::Templates::Engine.render(OPTIONS.merge(:object => o))
|
53
|
+
end
|
54
|
+
end.not_to output.to_stdout
|
55
|
+
#end.to raise_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# @rspec_example simple context can be instantiated
|
4
|
+
class SimpleClass
|
5
|
+
end
|
6
|
+
|
7
|
+
describe SimpleClass do
|
8
|
+
context 'with simple context' do
|
9
|
+
it 'can be instantiated' do
|
10
|
+
SimpleClass.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe SimpleClass do
|
16
|
+
subject {
|
17
|
+
YARD.parse(__FILE__)
|
18
|
+
output = YARD::Registry.all(:class).find { |i| i.to_s == 'SimpleClass' }
|
19
|
+
output = YARD::Templates::Engine.render(OPTIONS.merge(:object => output))
|
20
|
+
Nokogiri.HTML(output).css('.examples .inline').map(&:text)
|
21
|
+
}
|
22
|
+
|
23
|
+
it 'has the right example title' do
|
24
|
+
expect(subject).to include "\nSimpleClass with simple context can be instantiated\n"
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'yard'
|
5
|
+
require 'nokogiri'
|
6
|
+
require 'byebug'
|
1
7
|
require 'yard-rspec_examples'
|
8
|
+
|
2
9
|
require 'fixtures/example_file'
|
3
10
|
|
11
|
+
OPTIONS = {
|
12
|
+
:format => :html,
|
13
|
+
:template => :default,
|
14
|
+
:markup => :rdoc,
|
15
|
+
:serializer => YARD::Serializers::FileSystemSerializer.new,
|
16
|
+
:default_return => "Object",
|
17
|
+
:hide_void_return => false,
|
18
|
+
:no_highlight => false,
|
19
|
+
:files => []
|
20
|
+
}
|
21
|
+
|
4
22
|
RSpec.configure do |config|
|
5
23
|
|
6
24
|
end
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'yard'
|
3
|
-
EXAMPLE_DOC_DIR=[File.expand_path(File.dirname(__FILE__) + "/fixtures/*.rb"), File.expand_path(File.dirname(__FILE__) + "/*.rb")]
|
4
2
|
|
5
|
-
|
6
|
-
:format => :html,
|
7
|
-
:template => :default,
|
8
|
-
:markup => :rdoc,
|
9
|
-
:serializer => YARD::Serializers::FileSystemSerializer.new,
|
10
|
-
:default_return => "Object",
|
11
|
-
:hide_void_return => false,
|
12
|
-
:no_highlight => false,
|
13
|
-
:files => []
|
14
|
-
}
|
3
|
+
EXAMPLE_DOC_DIR=[File.expand_path(File.dirname(__FILE__) + "/fixtures/*.rb"), File.expand_path(File.dirname(__FILE__) + "/*.rb")]
|
15
4
|
|
16
5
|
describe "Using the rspec_example tag in the method comment" do
|
17
6
|
before(:each) do
|
@@ -24,11 +13,23 @@ describe "Using the rspec_example tag in the method comment" do
|
|
24
13
|
@nested_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => nested_class))
|
25
14
|
end
|
26
15
|
|
16
|
+
it "spawns no warnings on the fixtures" do
|
17
|
+
expect do
|
18
|
+
YARD.parse(EXAMPLE_DOC_DIR)
|
19
|
+
foo = YARD::Registry.all(:class).find { |i| i.to_s == "Foo" }
|
20
|
+
@class_foo_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => foo))
|
21
|
+
bar = YARD::Registry.all(:class).find { |i| i.to_s == "Foo::Bar" }
|
22
|
+
@class_bar_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => bar))
|
23
|
+
nested_class = YARD::Registry.all(:module).find { |i| i.to_s == "My" }
|
24
|
+
@nested_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => nested_class))
|
25
|
+
end.not_to output.to_stdout
|
26
|
+
end
|
27
|
+
|
27
28
|
it "displays warning on unfound example" do
|
28
29
|
expect do
|
29
30
|
invalid_class = YARD::Registry.all(:class).find { |i| i.to_s == "InvalidClass" }
|
30
31
|
@invalid_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => invalid_class))
|
31
|
-
end.to output("[warn] Could not find example 'InvalidClass
|
32
|
+
end.to output("[warn] Could not find example 'InvalidClass#some_method invalid'\n").to_stdout
|
32
33
|
end
|
33
34
|
|
34
35
|
it "creates an example tag in the registry" do
|
@@ -40,15 +41,22 @@ describe "Using the rspec_example tag in the method comment" do
|
|
40
41
|
end
|
41
42
|
|
42
43
|
it "includes the comments in the example as well" do
|
43
|
-
# TODO: comments as first line get stripped away right now.
|
44
44
|
expect(@class_foo_output).to match /With some comments/
|
45
45
|
end
|
46
46
|
|
47
|
+
it "supports single line do begin" do
|
48
|
+
expect(Nokogiri.HTML(@class_foo_output).css('.examples .example').map(&:text)).to include('"abracadabra"')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "supports curly braces syntax" do
|
52
|
+
expect(Nokogiri.HTML(@class_foo_output).css('.examples .example').map(&:text)).to include('"curly braces"')
|
53
|
+
end
|
54
|
+
|
47
55
|
it "works with nested classes" do
|
48
56
|
expect(@class_bar_output).to match /nested_class/
|
49
57
|
end
|
50
58
|
|
51
|
-
it "works with module/class/
|
59
|
+
it "works with module/class/class nestes classes" do
|
52
60
|
expect(@nested_class_output).to match /super_nested_class/
|
53
61
|
end
|
54
62
|
|
@@ -59,23 +67,18 @@ end
|
|
59
67
|
|
60
68
|
# A bit of a hack, this is the spec that is going to be used as fixture for the plugin
|
61
69
|
describe Foo do
|
62
|
-
|
70
|
+
context "#foo_method" do
|
63
71
|
it "works this way" do
|
64
|
-
this = "is"
|
65
|
-
just = "example code"
|
66
72
|
# With some comments
|
67
|
-
[1, 2, 3].each do |i|
|
68
|
-
i
|
69
|
-
end
|
70
73
|
end
|
71
74
|
|
72
75
|
it "also supports this" do
|
73
|
-
0 + 0
|
74
76
|
# comment for 'also support this' it
|
75
|
-
1 + 2
|
76
|
-
# kilo
|
77
|
-
4 + 3
|
78
77
|
end
|
78
|
+
|
79
|
+
it "supports single line do begin" do; "abracadabra" end
|
80
|
+
|
81
|
+
it("supports curly braces syntax"){"curly braces"}
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
@@ -86,6 +89,12 @@ describe Foo::Bar do
|
|
86
89
|
nested_class = nil
|
87
90
|
end
|
88
91
|
end
|
92
|
+
|
93
|
+
describe ".class_method" do
|
94
|
+
it 'is defined' do
|
95
|
+
Foo::Bar.class_method
|
96
|
+
end
|
97
|
+
end
|
89
98
|
end
|
90
99
|
|
91
100
|
module My
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-rspec_examples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert Bruynooghe
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -35,11 +35,11 @@ files:
|
|
35
35
|
- ".document"
|
36
36
|
- ".gitignore"
|
37
37
|
- ".rspec"
|
38
|
+
- ".travis.yml"
|
38
39
|
- ".yardopts"
|
39
40
|
- Gemfile
|
40
|
-
- Gemfile.lock
|
41
41
|
- LICENSE.txt
|
42
|
-
- README.
|
42
|
+
- README.md
|
43
43
|
- Rakefile
|
44
44
|
- lib/yard-rspec_examples.rb
|
45
45
|
- lib/yard/rspec_examples/describe_handler.rb
|
@@ -47,7 +47,13 @@ files:
|
|
47
47
|
- lib/yard/rspec_examples/module_handler.rb
|
48
48
|
- lib/yard/rspec_examples/parser_trace.rb
|
49
49
|
- lib/yard/rspec_examples/version.rb
|
50
|
+
- lib/yard/tags/rspec_example_tag.rb
|
50
51
|
- spec/fixtures/example_file.rb
|
52
|
+
- spec/inline_examples_spec.rb
|
53
|
+
- spec/named_examples_spec.rb
|
54
|
+
- spec/nested_class_spec.rb
|
55
|
+
- spec/nested_modules_spec.rb
|
56
|
+
- spec/simple_context_spec.rb
|
51
57
|
- spec/spec_helper.rb
|
52
58
|
- spec/yard-rspec_examples_spec.rb
|
53
59
|
- yard-rspec_examples.gemspec
|
@@ -76,6 +82,11 @@ specification_version: 4
|
|
76
82
|
summary: Yard plugin to include RSpec examples in documentation
|
77
83
|
test_files:
|
78
84
|
- spec/fixtures/example_file.rb
|
85
|
+
- spec/inline_examples_spec.rb
|
86
|
+
- spec/named_examples_spec.rb
|
87
|
+
- spec/nested_class_spec.rb
|
88
|
+
- spec/nested_modules_spec.rb
|
89
|
+
- spec/simple_context_spec.rb
|
79
90
|
- spec/spec_helper.rb
|
80
91
|
- spec/yard-rspec_examples_spec.rb
|
81
92
|
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
= yard-rspec_examples
|
2
|
-
|
3
|
-
Yard plugin to include examples in the generated doc through rspec
|
4
|
-
|
5
|
-
== Installation
|
6
|
-
|
7
|
-
In order to install it you just have to install it gem from gemcutter
|
8
|
-
|
9
|
-
gem install yard-rspec_examples
|
10
|
-
|
11
|
-
== Description
|
12
|
-
|
13
|
-
This plugin simply includes an example tag and recreates it with the source code that corresponds
|
14
|
-
to the first example included in the describe blocks below.
|
15
|
-
This have to be defined inside a describe block called "#method_name" that, in turn,
|
16
|
-
has to be defined in a describe block with the class name, i.e. the regular way people use rspec when testing objects.
|
17
|
-
|
18
|
-
So, for example,
|
19
|
-
|
20
|
-
Given this source code:
|
21
|
-
|
22
|
-
class Foo
|
23
|
-
##
|
24
|
-
# This is a foo method with an example
|
25
|
-
# @rspec_example
|
26
|
-
def foo_method
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
And this spec:
|
31
|
-
|
32
|
-
describe Foo do
|
33
|
-
describe "#foo_method" do
|
34
|
-
it "works this way" do
|
35
|
-
this = "is"
|
36
|
-
# The code that will be included in the example
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
A result like this is to be expected
|
42
|
-
class Foo
|
43
|
-
##
|
44
|
-
# This is a foo method with an example
|
45
|
-
# @example
|
46
|
-
# this = "is"
|
47
|
-
# # The code that will be included in the example
|
48
|
-
def foo_method
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
Another usage is to pass the example's name to the tag:
|
53
|
-
|
54
|
-
class Foo
|
55
|
-
##
|
56
|
-
# This is a foo method with an example
|
57
|
-
# @rspec_example works this way
|
58
|
-
def foo_method
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
== Using it
|
66
|
-
|
67
|
-
In order to use it, you just have to add the --plugin param plus yours
|
68
|
-
|
69
|
-
yardoc --plugin yar-rspec_examples [OPTS]
|
70
|
-
|
71
|
-
|
72
|
-
== Copyright
|
73
|
-
Copyright (c) 2011 Jose Fernandez (magec). See LICENSE.txt for
|
74
|
-
further details.
|
75
|
-
|