yard-rspec 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007-2009 Loren Segal
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ = Embedding RSpec Specifications in YARD Documentation
2
+
3
+ This plugin demonstrates how RSpec tests can be embedded within standard documentation
4
+ using only a small amount of plugin code. The example generates documentation
5
+ for the following {String#pig_latin} method and RSpec tests:
6
+
7
+ # Run `yardoc -e ../lib/yard-spec example_code.rb`
8
+
9
+ class String
10
+ # Pig latin of a String
11
+ def pig_latin
12
+ self[1..-1] + self[0] + "ay"
13
+ end
14
+ end
15
+
16
+ #
17
+ # Specs
18
+ #
19
+ describe String, '#pig_latin' do
20
+ it "should be a pig!" do
21
+ "hello".pig_latin.should == "ellohay"
22
+ end
23
+
24
+ it "should fail to be a pig!" do
25
+ "hello".pig_latin.should == "hello"
26
+ end
27
+ end
28
+
29
+ View the "Specifications" section within the {String#pig_latin} method to see
30
+ these tests.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+ require 'yard'
6
+
7
+ WINDOWS = (PLATFORM =~ /win32|cygwin/ ? true : false) rescue false
8
+ SUDO = WINDOWS ? '' : 'sudo'
9
+
10
+ task :default => :install
11
+
12
+ load 'yard-rspec.gemspec'
13
+ Rake::GemPackageTask.new(SPEC) do |pkg|
14
+ pkg.gem_spec = SPEC
15
+ pkg.need_zip = true
16
+ pkg.need_tar = true
17
+ end
18
+
19
+ desc "Install the gem locally"
20
+ task :install => :package do
21
+ sh "#{SUDO} gem install pkg/#{SPEC.name}-#{SPEC.version}.gem --local --no-rdoc --no-ri"
22
+ sh "rm -rf pkg/yard-#{SPEC.version}" unless ENV['KEEP_FILES']
23
+ end
24
+
25
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,30 @@
1
+ = Embedding RSpec Specifications in YARD Documentation
2
+
3
+ This plugin demonstrates how RSpec tests can be embedded within standard documentation
4
+ using only a small amount of plugin code. The example generates documentation
5
+ for the following {String#pig_latin} method and RSpec tests:
6
+
7
+ # Run `yardoc -e ../lib/yard-spec example_code.rb`
8
+
9
+ class String
10
+ # Pig latin of a String
11
+ def pig_latin
12
+ self[1..-1] + self[0] + "ay"
13
+ end
14
+ end
15
+
16
+ #
17
+ # Specs
18
+ #
19
+ describe String, '#pig_latin' do
20
+ it "should be a pig!" do
21
+ "hello".pig_latin.should == "ellohay"
22
+ end
23
+
24
+ it "should fail to be a pig!" do
25
+ "hello".pig_latin.should == "hello"
26
+ end
27
+ end
28
+
29
+ View the "Specifications" section within the {String#pig_latin} method to see
30
+ these tests.
@@ -0,0 +1,24 @@
1
+ # Run `yardoc -e ../lib/yard-spec example_code.rb`
2
+
3
+
4
+ class String
5
+ # Pig latin of a String
6
+ def pig_latin
7
+ self[1..-1] + self[0] + "ay"
8
+ end
9
+ end
10
+
11
+ #
12
+ # Specs
13
+ #
14
+ describe String do
15
+ describe '#pig_latin' do
16
+ it "should be a pig!" do
17
+ "hello".pig_latin.should == "ellohay"
18
+ end
19
+
20
+ it "should fail to be a pig!" do
21
+ "hello".pig_latin.should == "hello"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + '/../templates'
2
+ require File.join(File.dirname(__FILE__), 'yard-rspec', 'handler') if RUBY19
3
+ require File.join(File.dirname(__FILE__), 'yard-rspec', 'legacy')
@@ -0,0 +1,32 @@
1
+ class RSpecDescribeHandler < YARD::Handlers::Ruby::Base
2
+ handles method_call(:describe)
3
+
4
+ def process
5
+ objname = statement.parameters.first.jump(:string_content).source
6
+ if statement.parameters[1]
7
+ src = statement.parameters[1].jump(:string_content).source
8
+ objname += (src[0] == "#" ? "" : "::") + src
9
+ end
10
+ obj = {:spec => owner ? (owner[:spec] || "") : ""}
11
+ obj[:spec] += objname
12
+ parse_block(statement.last.last, owner: obj)
13
+ rescue YARD::Handlers::NamespaceMissingError
14
+ end
15
+ end
16
+
17
+ class RSpecItHandler < YARD::Handlers::Ruby::Base
18
+ handles method_call(:it)
19
+
20
+ def process
21
+ return if owner.nil?
22
+ obj = P(owner[:spec])
23
+ return if obj.is_a?(Proxy)
24
+
25
+ (obj[:specifications] ||= []) << {
26
+ name: statement.parameters.first.jump(:string_content).source,
27
+ file: statement.file,
28
+ line: statement.line,
29
+ source: statement.last.last.source.chomp
30
+ }
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ class LegacyRSpecDescribeHandler < YARD::Handlers::Ruby::Legacy::Base
2
+ MATCH = /\Adescribe\s+(.+?)\s+(do|\{)/
3
+ handles MATCH
4
+
5
+ def process
6
+ objname = statement.tokens.to_s[MATCH, 1].gsub(/["']/, '')
7
+ obj = {:spec => owner ? (owner[:spec] || "") : ""}
8
+ obj[:spec] += objname
9
+ parse_block :owner => obj
10
+ rescue YARD::Handlers::NamespaceMissingError
11
+ end
12
+ end
13
+
14
+ class LegacyRSpecItHandler < YARD::Handlers::Ruby::Legacy::Base
15
+ MATCH = /\Ait\s+['"](.+?)['"]\s+(do|\{)/
16
+ handles MATCH
17
+
18
+ def process
19
+ return if owner.nil?
20
+ obj = P(owner[:spec])
21
+ return if obj.is_a?(Proxy)
22
+
23
+ (obj[:specifications] ||= []) << {
24
+ :name => statement.tokens.to_s[MATCH, 1],
25
+ :file => parser.file,
26
+ :line => statement.line,
27
+ :source => statement.block.to_s
28
+ }
29
+ end
30
+ end
31
+
@@ -0,0 +1,28 @@
1
+ <% if object[:specifications] %>
2
+ <div class="tags">
3
+ <h3>Specifications:</h3>
4
+ <ul class="specs">
5
+ <% for spec in object[:specifications] %>
6
+ <li><%= spec[:name] %>
7
+ <div class="source_code">
8
+ <table>
9
+ <tr>
10
+ <td>
11
+ <pre class="lines">
12
+
13
+
14
+ <%= spec[:source].split("\n").size.times.to_a.map {|i| spec[:line] + i }.join("\n") %></pre>
15
+ </td>
16
+ <td>
17
+ <pre class="code"><span class="info file"># File '<%= h spec[:file] %>', line <%= spec[:line] %></span>
18
+
19
+ <%= html_syntax_highlight format_source(spec[:source]) %></pre>
20
+ </td>
21
+ </tr>
22
+ </table>
23
+ </div>
24
+ </li>
25
+ <% end %>
26
+ </ul>
27
+ </div>
28
+ <% end %>
@@ -0,0 +1,4 @@
1
+ def init
2
+ super
3
+ sections.last.place(:specs).before(:source)
4
+ end
@@ -0,0 +1,9 @@
1
+ <% if object[:specifications] %>
2
+
3
+ Specifications:
4
+ ---------------
5
+
6
+ <% for spec in object[:specifications] %>
7
+ <%= indent wrap("- " + spec[:name]) %>
8
+ <% end %>
9
+ <% end %>
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Loren Segal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-15 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yard
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: lsegal@soen.ca
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - example/example_code.rb
35
+ - example/README.rdoc
36
+ - lib/yard-rspec/handler.rb
37
+ - lib/yard-rspec/legacy.rb
38
+ - lib/yard-rspec.rb
39
+ - templates/default/method_details/html/specs.erb
40
+ - templates/default/method_details/setup.rb
41
+ - templates/default/method_details/text/specs.erb
42
+ - LICENSE
43
+ - README.rdoc
44
+ - Rakefile
45
+ has_rdoc: yard
46
+ homepage: http://yardoc.org
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: yard-rspec
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: YARD plugin to list RSpec specifications inside documentation
73
+ test_files: []
74
+