yard 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/ChangeLog +356 -0
- data/README.md +27 -5
- data/docs/GettingStarted.md +45 -6
- data/docs/Tags.md +16 -5
- data/docs/WhatsNew.md +60 -2
- data/lib/yard.rb +16 -37
- data/lib/yard/autoload.rb +5 -0
- data/lib/yard/cli/command.rb +18 -6
- data/lib/yard/cli/command_parser.rb +1 -0
- data/lib/yard/cli/config.rb +113 -0
- data/lib/yard/cli/gems.rb +16 -7
- data/lib/yard/cli/server.rb +30 -8
- data/lib/yard/cli/stats.rb +1 -1
- data/lib/yard/cli/yardoc.rb +16 -1
- data/lib/yard/code_objects/base.rb +7 -2
- data/lib/yard/code_objects/class_object.rb +1 -0
- data/lib/yard/code_objects/method_object.rb +1 -0
- data/lib/yard/code_objects/proxy.rb +8 -2
- data/lib/yard/config.rb +225 -0
- data/lib/yard/handlers/base.rb +29 -2
- data/lib/yard/handlers/processor.rb +1 -1
- data/lib/yard/handlers/ruby/class_handler.rb +6 -1
- data/lib/yard/handlers/ruby/constant_handler.rb +13 -15
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -1
- data/lib/yard/handlers/ruby/extend_handler.rb +3 -0
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -1
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +8 -10
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +3 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +13 -2
- data/lib/yard/handlers/ruby/method_handler.rb +1 -0
- data/lib/yard/handlers/ruby/mixin_handler.rb +14 -4
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +10 -1
- data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
- data/lib/yard/parser/c_parser.rb +26 -11
- data/lib/yard/parser/ruby/legacy/statement_list.rb +26 -9
- data/lib/yard/parser/source_parser.rb +5 -2
- data/lib/yard/serializers/yardoc_serializer.rb +2 -2
- data/lib/yard/server.rb +11 -0
- data/lib/yard/server/commands/frames_command.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +22 -13
- data/lib/yard/server/commands/library_index_command.rb +1 -0
- data/lib/yard/server/commands/search_command.rb +2 -0
- data/lib/yard/server/commands/static_file_command.rb +6 -1
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +3 -3
- data/lib/yard/templates/helpers/html_helper.rb +1 -1
- data/lib/yard/templates/helpers/markup_helper.rb +13 -12
- data/lib/yard/verifier.rb +3 -1
- data/spec/cli/config_spec.rb +72 -0
- data/spec/cli/gems_spec.rb +81 -0
- data/spec/cli/server_spec.rb +35 -5
- data/spec/cli/stats_spec.rb +15 -0
- data/spec/cli/yardoc_spec.rb +39 -1
- data/spec/code_objects/base_spec.rb +2 -0
- data/spec/code_objects/method_object_spec.rb +5 -0
- data/spec/code_objects/proxy_spec.rb +20 -5
- data/spec/config_spec.rb +165 -0
- data/spec/handlers/alias_handler_spec.rb +7 -0
- data/spec/handlers/base_spec.rb +64 -0
- data/spec/handlers/class_condition_handler_spec.rb +13 -8
- data/spec/handlers/class_handler_spec.rb +54 -46
- data/spec/handlers/constant_handler_spec.rb +13 -0
- data/spec/handlers/examples/alias_handler_001.rb.txt +2 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +12 -1
- data/spec/handlers/examples/constant_handler_001.rb.txt +6 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +8 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +6 -0
- data/spec/handlers/examples/visibility_handler_001.rb.txt +3 -0
- data/spec/handlers/exception_handler_spec.rb +5 -0
- data/spec/handlers/extend_handler_spec.rb +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/mixin_handler_spec.rb +10 -0
- data/spec/handlers/visibility_handler_spec.rb +4 -0
- data/spec/parser/base_spec.rb +1 -1
- data/spec/parser/c_parser_spec.rb +39 -1
- data/spec/parser/examples/override.c.txt +424 -0
- data/spec/parser/ruby/legacy/statement_list_spec.rb +11 -0
- data/spec/parser/source_parser_spec.rb +33 -1
- data/spec/server/commands/static_file_command_spec.rb +20 -3
- data/spec/server_spec.rb +10 -0
- data/spec/templates/examples/method001.html +33 -3
- data/spec/templates/examples/method001.txt +8 -1
- data/spec/templates/helpers/markup_helper_spec.rb +21 -26
- data/spec/templates/method_spec.rb +3 -1
- data/spec/verifier_spec.rb +5 -0
- data/templates/default/fulldoc/html/css/style.css +4 -1
- data/templates/default/fulldoc/html/js/app.js +1 -1
- data/templates/default/tags/html/option.erb +1 -3
- data/templates/default/tags/setup.rb +18 -15
- metadata +11 -4
- data/spec/yard_spec.rb +0 -55
data/spec/cli/server_spec.rb
CHANGED
@@ -1,20 +1,27 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
+
class Server::WebrickAdapter; def start; end end
|
4
|
+
|
3
5
|
describe YARD::CLI::Server do
|
4
6
|
before do
|
5
7
|
@no_verify_libraries = false
|
8
|
+
@no_adapter_mock = false
|
6
9
|
@libraries = {}
|
7
10
|
@options = {:single_library => true, :caching => false}
|
8
11
|
@server_options = {:Port => 8808}
|
9
12
|
@adapter = mock(:adapter)
|
13
|
+
@adapter.stub!(:setup)
|
10
14
|
@cli = YARD::CLI::Server.new
|
11
|
-
@cli.stub!(:adapter).and_return(@adapter)
|
12
15
|
end
|
13
16
|
|
14
17
|
def rack_required
|
15
18
|
begin; require 'rack'; rescue LoadError; pending "rack required for this test" end
|
16
19
|
end
|
17
20
|
|
21
|
+
def unstub_adapter
|
22
|
+
@no_adapter_mock = true
|
23
|
+
end
|
24
|
+
|
18
25
|
def run(*args)
|
19
26
|
if @libraries.empty?
|
20
27
|
library = Server::LibraryVersion.new(File.basename(Dir.pwd), nil, '.yardoc')
|
@@ -23,8 +30,11 @@ describe YARD::CLI::Server do
|
|
23
30
|
unless @no_verify_libraries
|
24
31
|
@libraries.values.each {|libs| libs.each {|lib| File.should_receive(:exist?).at_least(1).times.with(lib.yardoc_file).and_return(true) } }
|
25
32
|
end
|
26
|
-
|
27
|
-
|
33
|
+
unless @no_adapter_mock
|
34
|
+
@cli.stub!(:adapter).and_return(@adapter)
|
35
|
+
@adapter.should_receive(:new).with(@libraries, @options, @server_options).and_return(@adapter)
|
36
|
+
@adapter.should_receive(:start)
|
37
|
+
end
|
28
38
|
@cli.run(*args.flatten)
|
29
39
|
end
|
30
40
|
|
@@ -94,7 +104,6 @@ describe YARD::CLI::Server do
|
|
94
104
|
|
95
105
|
it "should default to Rack adapter if exists on system" do
|
96
106
|
rack_required
|
97
|
-
@cli.unstub(:adapter)
|
98
107
|
@cli.should_receive(:require).with('rubygems').and_return(false)
|
99
108
|
@cli.should_receive(:require).with('rack').and_return(true)
|
100
109
|
@cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
|
@@ -102,7 +111,6 @@ describe YARD::CLI::Server do
|
|
102
111
|
end
|
103
112
|
|
104
113
|
it "should fall back to WEBrick adapter if Rack is not on system" do
|
105
|
-
@cli.unstub(:adapter)
|
106
114
|
@cli.should_receive(:require).with('rubygems').and_return(false)
|
107
115
|
@cli.should_receive(:require).with('rack').and_raise(LoadError)
|
108
116
|
@cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
|
@@ -137,4 +145,26 @@ describe YARD::CLI::Server do
|
|
137
145
|
run '-g'
|
138
146
|
run '--gems'
|
139
147
|
end
|
148
|
+
|
149
|
+
it "should load template paths after adapter template paths" do
|
150
|
+
unstub_adapter
|
151
|
+
@cli.adapter = Server::WebrickAdapter
|
152
|
+
run '-t', 'foo'
|
153
|
+
Templates::Engine.template_paths.last.should == 'foo'
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should load ruby code (-e) after adapter" do
|
157
|
+
unstub_adapter
|
158
|
+
@cli.adapter = Server::WebrickAdapter
|
159
|
+
File.open(File.dirname(__FILE__) + '/tmp.adapterscript.rb', 'w') do |f|
|
160
|
+
begin
|
161
|
+
f.puts "YARD::Templates::Engine.register_template_path 'foo'"
|
162
|
+
f.flush
|
163
|
+
run '-e', f.path
|
164
|
+
Templates::Engine.template_paths.last.should == 'foo'
|
165
|
+
ensure
|
166
|
+
File.unlink(f.path)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
140
170
|
end
|
data/spec/cli/stats_spec.rb
CHANGED
@@ -45,6 +45,21 @@ A#foo
|
|
45
45
|
eof
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should list no undocumented objects with --list-undoc when objects are undocumented" do
|
49
|
+
Registry.clear
|
50
|
+
YARD.parse_string <<-eof
|
51
|
+
# documentation
|
52
|
+
def foo; end
|
53
|
+
eof
|
54
|
+
@stats.run('--list-undoc')
|
55
|
+
@output.string.should == "Files: 1\n" +
|
56
|
+
"Modules: 0 ( 0 undocumented)\n" +
|
57
|
+
"Classes: 0 ( 0 undocumented)\n" +
|
58
|
+
"Constants: 0 ( 0 undocumented)\n" +
|
59
|
+
"Methods: 1 ( 0 undocumented)\n" +
|
60
|
+
" 100.00% documented\n"
|
61
|
+
end
|
62
|
+
|
48
63
|
it "should list undocumented objects in compact mode with --list-undoc --compact" do
|
49
64
|
@stats.run('--list-undoc', '--compact')
|
50
65
|
@output.string.should == <<-eof
|
data/spec/cli/yardoc_spec.rb
CHANGED
@@ -261,7 +261,7 @@ describe YARD::CLI::Yardoc do
|
|
261
261
|
|
262
262
|
it "should not call #tag on namespace if namespace is proxy with --no-private" do
|
263
263
|
ns = mock(:namespace)
|
264
|
-
ns.
|
264
|
+
ns.should_receive(:is_a?).with(CodeObjects::Proxy).and_return(true)
|
265
265
|
ns.should_not_receive(:tag)
|
266
266
|
obj = mock(:object)
|
267
267
|
obj.stub!(:type).and_return(:class)
|
@@ -272,6 +272,21 @@ describe YARD::CLI::Yardoc do
|
|
272
272
|
@yardoc.options[:verifier].call(obj).should == true
|
273
273
|
end
|
274
274
|
|
275
|
+
# @bug gh-197
|
276
|
+
it "should not call #tag on namespace if namespace is proxy with --no-private" do
|
277
|
+
Registry.clear
|
278
|
+
YARD.parse_string "module Qux; class Foo::Bar; end; end"
|
279
|
+
foobar = Registry.at('Foo::Bar')
|
280
|
+
foobar.namespace.type = :module
|
281
|
+
@yardoc.parse_arguments *%w( --no-private )
|
282
|
+
@yardoc.options[:verifier].call(foobar).should == true
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should not call #tag on proxy object" do # @bug gh-197
|
286
|
+
@yardoc.parse_arguments *%w( --no-private )
|
287
|
+
@yardoc.options[:verifier].call(P('ProxyClass')).should == true
|
288
|
+
end
|
289
|
+
|
275
290
|
it "should hide methods inside a 'private' class/module with --no-private" do
|
276
291
|
Registry.clear
|
277
292
|
YARD.parse_string <<-eof
|
@@ -467,4 +482,27 @@ describe YARD::CLI::Yardoc do
|
|
467
482
|
Tags::Library.transitive_tags.should include(:foo)
|
468
483
|
end
|
469
484
|
end
|
485
|
+
|
486
|
+
describe 'Safe mode' do
|
487
|
+
before do
|
488
|
+
YARD::Config.stub!(:options).and_return(:safe_mode => true)
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should not allow --load or -e in safe mode" do
|
492
|
+
@yardoc.should_not_receive(:require)
|
493
|
+
@yardoc.run('--load', 'foo')
|
494
|
+
@yardoc.run('-e', 'foo')
|
495
|
+
end
|
496
|
+
|
497
|
+
it "should not allow --query in safe mode" do
|
498
|
+
@yardoc.run('--query', 'foo')
|
499
|
+
@yardoc.options[:verifier].expressions.should_not include("foo")
|
500
|
+
end
|
501
|
+
|
502
|
+
it "should not allow modifying the template paths" do
|
503
|
+
YARD::Templates::Engine.should_not_receive(:register_template_path)
|
504
|
+
@yardoc.run('-p', 'foo')
|
505
|
+
@yardoc.run('--template-path', 'foo')
|
506
|
+
end
|
507
|
+
end
|
470
508
|
end
|
@@ -240,6 +240,8 @@ describe YARD::CodeObjects::Base do
|
|
240
240
|
Registry.at('C::B::C::Apple').relative_path('C::B::C::Ant').should == 'Ant'
|
241
241
|
YARD.parse_string 'module OMG::ABC; end; class Object; end'
|
242
242
|
Registry.at('OMG::ABC').relative_path('Object').should == "Object"
|
243
|
+
YARD.parse_string("class YARD::Config; MYCONST = 1; end")
|
244
|
+
Registry.at('YARD::Config').relative_path('YARD::Config::MYCONST').should == "MYCONST"
|
243
245
|
end
|
244
246
|
|
245
247
|
it "should return a relative path for class methods" do
|
@@ -143,5 +143,10 @@ describe YARD::CodeObjects::MethodObject do
|
|
143
143
|
eof
|
144
144
|
Registry.at('B#foo').overridden_method.should be_nil
|
145
145
|
end
|
146
|
+
|
147
|
+
it "should return nil if namespace is a proxy" do
|
148
|
+
YARD.parse_string "def ARGV.foo; end"
|
149
|
+
Registry.at('ARGV.foo').overridden_method.should be_nil
|
150
|
+
end
|
146
151
|
end
|
147
152
|
end
|
@@ -38,11 +38,10 @@ describe YARD::CodeObjects::Proxy do
|
|
38
38
|
P(:YARD).respond_to?(:children).should == true
|
39
39
|
P(:NOTYARD).respond_to?(:children).should == false
|
40
40
|
|
41
|
-
|
42
|
-
P(:YARD).respond_to?(
|
43
|
-
P(:
|
44
|
-
P(:NOTYARD).respond_to?(
|
45
|
-
P(:NOTYARD).respond_to?(private_method, true).should == true
|
41
|
+
P(:YARD).respond_to?(:initialize).should == false
|
42
|
+
P(:YARD).respond_to?(:initialize, true).should == true
|
43
|
+
P(:NOTYARD).respond_to?(:initialize).should == false
|
44
|
+
P(:NOTYARD).respond_to?(:initialize, true).should == true
|
46
45
|
end
|
47
46
|
|
48
47
|
it "should make itself obvious that it's a proxy" do
|
@@ -97,4 +96,20 @@ describe YARD::CodeObjects::Proxy do
|
|
97
96
|
resolved.namespace.should == Registry.root
|
98
97
|
resolved.name.should == :YARD
|
99
98
|
end
|
99
|
+
|
100
|
+
it "should ensure that the correct object was resolved" do
|
101
|
+
foo = ModuleObject.new(:root, :Foo)
|
102
|
+
foobar = ModuleObject.new(foo, :Bar)
|
103
|
+
foobaz = ClassObject.new(foo, :Baz)
|
104
|
+
|
105
|
+
# Remember, we're looking for Qux::Bar, not just 'Bar'
|
106
|
+
proxy = Proxy.new(foobar, 'Foo::Qux::Bar')
|
107
|
+
proxy.type.should == :proxy
|
108
|
+
|
109
|
+
qux = ModuleObject.new(foo, :Qux)
|
110
|
+
quxbar = ModuleObject.new(qux, :Bar)
|
111
|
+
|
112
|
+
# Now it should resolve
|
113
|
+
proxy.type.should == :module
|
114
|
+
end
|
100
115
|
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe YARD::Config do
|
4
|
+
describe '.load' do
|
5
|
+
before do
|
6
|
+
File.should_receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should use default options if no ~/.yard/config is found" do
|
10
|
+
File.should_receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
|
11
|
+
File.should_receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
|
12
|
+
YARD::Config.load
|
13
|
+
YARD::Config.options.should == YARD::Config::DEFAULT_CONFIG_OPTIONS
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should overwrite options with data in ~/.yard/config" do
|
17
|
+
File.should_receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(true)
|
18
|
+
File.should_receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(true)
|
19
|
+
YAML.should_receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return({'test' => true})
|
20
|
+
YARD::Config.load
|
21
|
+
YARD::Config.options[:test].should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should ignore any plugins specified in '~/.yard/ignored_plugins'" do
|
25
|
+
File.should_receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
|
26
|
+
File.should_receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(true)
|
27
|
+
File.should_receive(:read).with(YARD::Config::IGNORED_PLUGINS).and_return('yard-plugin plugin2')
|
28
|
+
YARD::Config.load
|
29
|
+
YARD::Config.options[:ignored_plugins].should == ['yard-plugin', 'yard-plugin2']
|
30
|
+
YARD::Config.should_not_receive(:require).with('yard-plugin2')
|
31
|
+
YARD::Config.load_plugin('yard-plugin2').should == false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.save' do
|
36
|
+
it "should save options to config file" do
|
37
|
+
YARD::Config.stub!(:options).and_return(:a => 1, :b => %w(a b c))
|
38
|
+
file = mock(:file)
|
39
|
+
File.should_receive(:open).with(YARD::Config::CONFIG_FILE, 'w').and_yield(file)
|
40
|
+
file.should_receive(:write).with(YAML.dump(:a => 1, :b => %w(a b c)))
|
41
|
+
YARD::Config.save
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.load_plugin' do
|
46
|
+
it "should load a plugin by 'name' as 'yard-name'" do
|
47
|
+
YARD::Config.should_receive(:require).with('yard-foo')
|
48
|
+
log.should_receive(:debug).with(/Loading plugin 'yard-foo'/).once
|
49
|
+
YARD::Config.load_plugin('foo').should == true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not load plugins like 'doc-*'" do
|
53
|
+
YARD::Config.should_not_receive(:require).with('yard-doc-core')
|
54
|
+
YARD::Config.load_plugin('doc-core')
|
55
|
+
YARD::Config.load_plugin('yard-doc-core')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should load plugin by 'yard-name' as 'yard-name'" do
|
59
|
+
YARD::Config.should_receive(:require).with('yard-foo')
|
60
|
+
log.should_receive(:debug).with(/Loading plugin 'yard-foo'/).once
|
61
|
+
YARD::Config.load_plugin('yard-foo').should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should load plugin by 'yard_name' as 'yard_name'" do
|
65
|
+
YARD::Config.should_receive(:require).with('yard_foo')
|
66
|
+
log.should_receive(:debug).with(/Loading plugin 'yard_foo'/).once
|
67
|
+
log.show_backtraces = false
|
68
|
+
YARD::Config.load_plugin('yard_foo').should == true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should log error if plugin is not found" do
|
72
|
+
YARD::Config.should_receive(:require).with('yard-foo').and_raise(LoadError)
|
73
|
+
log.should_receive(:warn).with(/Error loading plugin 'yard-foo'/).once
|
74
|
+
YARD::Config.load_plugin('yard-foo').should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should sanitize plugin name (remove /'s)" do
|
78
|
+
YARD::Config.should_receive(:require).with('yard-foofoo')
|
79
|
+
YARD::Config.load_plugin('foo/foo').should == true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should ignore plugins in :ignore_plugins" do
|
83
|
+
YARD::Config.stub!(:options).and_return(:ignored_plugins => ['yard-foo', 'yard-bar'])
|
84
|
+
YARD::Config.load_plugin('foo').should == false
|
85
|
+
YARD::Config.load_plugin('bar').should == false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.load_plugins' do
|
90
|
+
it "should load gem plugins if :load_plugins is true" do
|
91
|
+
File.should_receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
|
92
|
+
YARD::Config.stub!(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
|
93
|
+
YARD::Config.should_receive(:require).with('rubygems')
|
94
|
+
YARD::Config.load_plugins
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should ignore gem loading if RubyGems cannot load" do
|
98
|
+
YARD::Config.stub!(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
|
99
|
+
YARD::Config.should_receive(:require).with('rubygems').and_raise(LoadError)
|
100
|
+
YARD::Config.load_plugins.should == false
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should load certain plugins automatically when specified in :autoload_plugins" do
|
104
|
+
File.should_receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
|
105
|
+
YARD::Config.stub!(:options).and_return(:load_plugins => false, :ignored_plugins => [], :autoload_plugins => ['yard-plugin'])
|
106
|
+
YARD::Config.should_receive(:require).with('yard-plugin').and_return(true)
|
107
|
+
YARD::Config.load_plugins.should == true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should parse --plugin from command line arguments" do
|
111
|
+
YARD::Config.should_receive(:arguments).at_least(1).times.and_return(%w(--plugin foo --plugin bar a b c))
|
112
|
+
YARD::Config.should_receive(:load_plugin).with('foo').and_return(true)
|
113
|
+
YARD::Config.should_receive(:load_plugin).with('bar').and_return(true)
|
114
|
+
YARD::Config.load_plugins.should == true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should load --plugin arguments from .yardopts" do
|
118
|
+
File.should_receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).once.and_return(true)
|
119
|
+
File.should_receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
|
120
|
+
File.should_receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
|
121
|
+
File.should_receive(:read_binary).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).once.and_return('--plugin foo')
|
122
|
+
YARD::Config.should_receive(:load_plugin).with('foo')
|
123
|
+
YARD::Config.load
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should load any gem plugins starting with 'yard_' or 'yard-'" do
|
127
|
+
File.should_receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
|
128
|
+
YARD::Config.stub!(:options).and_return(:load_plugins => true, :ignored_plugins => ['yard_plugin'], :autoload_plugins => [])
|
129
|
+
plugins = {
|
130
|
+
'yard' => mock('yard'),
|
131
|
+
'yard_plugin' => mock('yard_plugin'),
|
132
|
+
'yard-plugin' => mock('yard-plugin'),
|
133
|
+
'my-yard-plugin' => mock('yard-plugin'),
|
134
|
+
'rspec' => mock('rspec'),
|
135
|
+
}
|
136
|
+
plugins.each do |k, v|
|
137
|
+
v.should_receive(:name).at_least(1).times.and_return(k)
|
138
|
+
end
|
139
|
+
|
140
|
+
source_mock = mock(:source_index)
|
141
|
+
source_mock.should_receive(:find_name).with('').and_return(plugins.values)
|
142
|
+
Gem.should_receive(:source_index).and_return(source_mock)
|
143
|
+
YARD::Config.should_receive(:load_plugin).with('yard_plugin').and_return(false)
|
144
|
+
YARD::Config.should_receive(:load_plugin).with('yard-plugin').and_return(true)
|
145
|
+
YARD::Config.load_plugins.should == true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should log an error if a gem raises an error" do
|
149
|
+
YARD::Config.stub!(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
|
150
|
+
plugins = {
|
151
|
+
'yard-plugin' => mock('yard-plugin')
|
152
|
+
}
|
153
|
+
plugins.each do |k, v|
|
154
|
+
v.should_receive(:name).at_least(1).times.and_return(k)
|
155
|
+
end
|
156
|
+
|
157
|
+
source_mock = mock(:source_index)
|
158
|
+
source_mock.should_receive(:find_name).with('').and_return(plugins.values)
|
159
|
+
Gem.should_receive(:source_index).and_return(source_mock)
|
160
|
+
YARD::Config.should_receive(:load_plugin).with('yard-plugin').and_raise(Gem::LoadError)
|
161
|
+
log.should_receive(:warn).with(/Error loading plugin 'yard-plugin'/)
|
162
|
+
YARD::Config.load_plugins.should == false
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -48,6 +48,13 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AliasHandler" do
|
|
48
48
|
P('B#for').should be_instance_of(CodeObjects::MethodObject)
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should handle keywords in alias names" do
|
52
|
+
P('B#do').is_alias?.should == true
|
53
|
+
P('B#x2').is_alias?.should == true
|
54
|
+
P(:B).aliases[P('B#do')].should == :x
|
55
|
+
P(:B).aliases[P('B#x2')].should == :do
|
56
|
+
end
|
57
|
+
|
51
58
|
it "should raise an UndocumentableError if only one parameter is passed" do
|
52
59
|
undoc_error "alias_method :q"
|
53
60
|
end
|
data/spec/handlers/base_spec.rb
CHANGED
@@ -108,4 +108,68 @@ describe YARD::Handlers::Base do
|
|
108
108
|
process PushStateHandler3
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
describe '.in_file' do
|
113
|
+
def parse(filename, src = "class A; end")
|
114
|
+
parser = Parser::SourceParser.new
|
115
|
+
parser.instance_variable_set("@file", filename)
|
116
|
+
parser.parse(StringIO.new(src))
|
117
|
+
end
|
118
|
+
|
119
|
+
def create_handler(stmts)
|
120
|
+
@@counter ||= 0
|
121
|
+
sklass = Parser::SourceParser.parser_type == :ruby ? "Base" : "Legacy::Base"
|
122
|
+
instance_eval(<<-eof)
|
123
|
+
class ::InFileHandler#{@@counter += 1} < Handlers::Ruby::#{sklass}
|
124
|
+
handles /^class/
|
125
|
+
#{stmts}
|
126
|
+
def process; MethodObject.new(:root, :FOO) end
|
127
|
+
end
|
128
|
+
eof
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_handler(file, stmts, creates = true)
|
132
|
+
Registry.clear
|
133
|
+
Registry.at('#FOO').should be_nil
|
134
|
+
create_handler(stmts)
|
135
|
+
parse(file)
|
136
|
+
Registry.at('#FOO').send(creates ? :should_not : :should, be_nil)
|
137
|
+
Handlers::Base.subclasses.delete_if {|k,v| k.to_s =~ /^InFileHandler/ }
|
138
|
+
end
|
139
|
+
|
140
|
+
[:ruby, :ruby18].each do |parser_type|
|
141
|
+
next if parser_type == :ruby && !RUBY19
|
142
|
+
describe "Parser type = #{parser_type.inspect}" do
|
143
|
+
Parser::SourceParser.parser_type = parser_type
|
144
|
+
it "should allow handler to be specific to a file" do
|
145
|
+
test_handler 'file_a.rb', 'in_file "file_a.rb"', true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should ignore handler if filename does not match" do
|
149
|
+
test_handler 'file_b.rb', 'in_file "file_a.rb"', false
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should only test filename part when given a String" do
|
153
|
+
test_handler '/path/to/file_a.rb', 'in_file "/to/file_a.rb"', false
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should test exact match for entire String" do
|
157
|
+
test_handler 'file_a.rb', 'in_file "file"', false
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should allow a Regexp as argument and test against full path" do
|
161
|
+
test_handler 'file_a.rbx', 'in_file /\.rbx$/', true
|
162
|
+
test_handler '/path/to/file_a.rbx', 'in_file /\/to\/file_/', true
|
163
|
+
test_handler '/path/to/file_a.rbx', 'in_file /^\/path/', true
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should allow multiple in_file declarations" do
|
167
|
+
stmts = 'in_file "x"; in_file /y/; in_file "foo.rb"'
|
168
|
+
test_handler 'foo.rb', stmts, true
|
169
|
+
test_handler 'xyzzy.rb', stmts, true
|
170
|
+
test_handler 'x', stmts, true
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
111
175
|
end
|