yard-different-rspec 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = Forked - Changes ...
2
+
3
+ We don't write our specs like:
4
+
5
+ describe Object
6
+ describe '#method_name'
7
+
8
+ We write
9
+
10
+ describe 'Some Feature'
11
+ it 'can do this or that'
12
+
13
+ I would like to be able to easily associate these with methods so I've tweaked this to support:
14
+
15
+ describe 'Some Feature'
16
+ it 'can do this or that [Object#whatever]'
17
+
18
+ You can associate an example with multiple objects too:
19
+
20
+ describe 'Some Feature'
21
+ it 'can do this or that [Object#whatever][AnotherObject#method]'
22
+
23
+ = Embedding RSpec Specifications in YARD Documentation
24
+
25
+ This plugin demonstrates how RSpec tests can be embedded within standard documentation
26
+ using only a small amount of plugin code. The example generates documentation
27
+ for the following {String#pig_latin} method and RSpec tests:
28
+
29
+ # Run `yardoc -e ../lib/yard-rspec example_code.rb`
30
+
31
+ class String
32
+ # Pig latin of a String
33
+ def pig_latin
34
+ self[1..-1] + self[0] + "ay"
35
+ end
36
+ end
37
+
38
+ #
39
+ # Specs
40
+ #
41
+ describe String, '#pig_latin' do
42
+ it "should be a pig!" do
43
+ "hello".pig_latin.should == "ellohay"
44
+ end
45
+
46
+ it "should fail to be a pig!" do
47
+ "hello".pig_latin.should == "hello"
48
+ end
49
+ end
50
+
51
+ View the "Specifications" section within the {String#pig_latin} method to see
52
+ these tests.
data/Rakefile ADDED
@@ -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-rspec 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,43 @@
1
+ # Run `yardoc -e ../lib/yard-rspec 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
+
10
+ def something_else
11
+ end
12
+ end
13
+
14
+ #
15
+ # Specs
16
+ #
17
+ describe String do
18
+ describe '#pig_latin' do
19
+ it "should be a pig!" do
20
+ "hello".pig_latin.should == "ellohay"
21
+ end
22
+
23
+ it "should fail to be a pig!" do
24
+ "hello".pig_latin.should == "hello"
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'Some Feature' do
30
+
31
+ it 'should do cool things' do
32
+ pending
33
+ end
34
+
35
+ it 'should do other things [String#pig_latin][String#something_else]' do
36
+ pending
37
+ end
38
+
39
+ it 'should do neat things' do
40
+ pending
41
+ end
42
+
43
+ end
data/lib/yard-rspec.rb ADDED
@@ -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,38 @@
1
+ class LegacyRSpecDescribeHandler < YARD::Handlers::Ruby::Legacy::Base
2
+ MATCH = /\Adescribe\s+(.+?)\s+(do|\{)/
3
+ handles MATCH
4
+
5
+ # I'm not using this logic anymore but if I remove it, nothing works Oo
6
+ def process
7
+ objname = statement.tokens.to_s[MATCH, 1].gsub(/["']/, '')
8
+ obj = {:spec => owner ? (owner[:spec] || "") : ""}
9
+ obj[:spec] += objname
10
+ parse_block :owner => obj
11
+ rescue YARD::Handlers::NamespaceMissingError
12
+ end
13
+ end
14
+
15
+ class LegacyRSpecItHandler < YARD::Handlers::Ruby::Legacy::Base
16
+ MATCH = /\Ait\s+['"](.+?)['"]\s+(do|\{)/
17
+ handles MATCH
18
+
19
+ def process
20
+ example_name = statement.tokens.to_s[MATCH, 1]
21
+ object_names = example_name.scan(/\[([^\]]+)\]/)
22
+ example_name_without_objects = example_name.gsub(/\[.+\]/, '').strip
23
+
24
+ return if object_names.empty?
25
+
26
+ object_names.each do |object_name|
27
+ obj = P(object_name)
28
+ next if obj.is_a?(Proxy)
29
+
30
+ (obj[:specifications] ||= []) << {
31
+ :name => example_name_without_objects,
32
+ :file => parser.file,
33
+ :line => statement.line,
34
+ :source => statement.block.to_s
35
+ }
36
+ end
37
+ end
38
+ end
@@ -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,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-different-rspec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - remi
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-04-27 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: yard
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ version: "0"
29
+ type: :runtime
30
+ version_requirements: *id001
31
+ description:
32
+ email: remi@remitaylor.com
33
+ executables: []
34
+
35
+ extensions: []
36
+
37
+ extra_rdoc_files: []
38
+
39
+ files:
40
+ - example/README.rdoc
41
+ - example/example_code.rb
42
+ - lib/yard-rspec/legacy.rb
43
+ - lib/yard-rspec/handler.rb
44
+ - lib/yard-rspec.rb
45
+ - templates/default/method_details/setup.rb
46
+ - templates/default/method_details/html/specs.erb
47
+ - templates/default/method_details/text/specs.erb
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ has_rdoc: yard
52
+ homepage: http://github.com/remi/yard-spec-plugin
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project: yard-rspec
77
+ rubygems_version: 1.3.6
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Forked YARD plugin to list RSpec specifications inside documentation
81
+ test_files: []
82
+