yard 0.5.8 → 0.6.0
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/.yardopts +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- metadata +80 -10
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
describe YARD::CLI::Diff do
|
6
|
+
before do
|
7
|
+
CLI::Yardoc.stub!(:run)
|
8
|
+
CLI::Gems.stub!(:run)
|
9
|
+
@diff = CLI::Diff.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Argument handling' do
|
13
|
+
it "should exit if there is only one gem name" do
|
14
|
+
@diff.should_receive(:exit)
|
15
|
+
@diff.should_receive(:puts).with(/Usage/)
|
16
|
+
@diff.run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'Diffing' do
|
21
|
+
before do
|
22
|
+
@objects1 = nil
|
23
|
+
@objects2 = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def run(*args)
|
27
|
+
@data = StringIO.new
|
28
|
+
@objects1 ||= %w( C#fooey C#baz D.bar )
|
29
|
+
@objects2 ||= %w( A A::B A::B::C A.foo A#foo B C.foo C.bar C#baz )
|
30
|
+
@diff.should_receive(:load_gem_data).ordered.with('gem1').and_return(true)
|
31
|
+
@diff.should_receive(:load_gem_data).ordered.with('gem2').and_return(true)
|
32
|
+
Registry.should_receive(:all).ordered.and_return(@objects1.map {|o| P(o) })
|
33
|
+
Registry.should_receive(:all).ordered.and_return(@objects2.map {|o| P(o) })
|
34
|
+
@diff.stub!(:print).with {|data| @data << data }
|
35
|
+
@diff.stub!(:puts).with {|*args| @data << args.join("\n"); @data << "\n" }
|
36
|
+
@diff.run(*(args + ['gem1', 'gem2']))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should show differences between objects" do
|
40
|
+
run
|
41
|
+
@data.string.should == <<-eof
|
42
|
+
Added objects:
|
43
|
+
|
44
|
+
A (...)
|
45
|
+
B
|
46
|
+
C.bar
|
47
|
+
C.foo
|
48
|
+
|
49
|
+
Removed objects:
|
50
|
+
|
51
|
+
C#fooey
|
52
|
+
D.bar
|
53
|
+
|
54
|
+
eof
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should accept -a/--all" do
|
58
|
+
['-a', '--all'].each do |opt|
|
59
|
+
run(opt)
|
60
|
+
@data.string.should == <<-eof
|
61
|
+
Added objects:
|
62
|
+
|
63
|
+
A
|
64
|
+
A#foo
|
65
|
+
A.foo
|
66
|
+
A::B
|
67
|
+
A::B::C
|
68
|
+
B
|
69
|
+
C.bar
|
70
|
+
C.foo
|
71
|
+
|
72
|
+
Removed objects:
|
73
|
+
|
74
|
+
C#fooey
|
75
|
+
D.bar
|
76
|
+
|
77
|
+
eof
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'File searching' do
|
83
|
+
before do
|
84
|
+
@diff.stub!(:generate_yardoc)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should search for gem/.yardoc" do
|
88
|
+
File.should_receive(:directory?).with('gem1/.yardoc').and_return(true)
|
89
|
+
File.should_receive(:directory?).with('gem2/.yardoc').and_return(true)
|
90
|
+
Registry.should_receive(:load_yardoc).with('gem1/.yardoc')
|
91
|
+
Registry.should_receive(:load_yardoc).with('gem2/.yardoc')
|
92
|
+
@diff.run('gem1', 'gem2')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should search for argument as yardoc" do
|
96
|
+
File.should_receive(:directory?).with('gem1/.yardoc').and_return(false)
|
97
|
+
File.should_receive(:directory?).with('gem2/.yardoc').and_return(false)
|
98
|
+
File.should_receive(:directory?).with('gem1').and_return(true)
|
99
|
+
File.should_receive(:directory?).with('gem2').and_return(true)
|
100
|
+
Registry.should_receive(:load_yardoc).with('gem1')
|
101
|
+
Registry.should_receive(:load_yardoc).with('gem2')
|
102
|
+
@diff.run('gem1', 'gem2')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should search for installed gem" do
|
106
|
+
File.should_receive(:directory?).with('gem1-1.0.0.gem/.yardoc').and_return(false)
|
107
|
+
File.should_receive(:directory?).with('gem2-1.0.0/.yardoc').and_return(false)
|
108
|
+
File.should_receive(:directory?).with('gem1-1.0.0.gem').and_return(false)
|
109
|
+
File.should_receive(:directory?).with('gem2-1.0.0').and_return(false)
|
110
|
+
gemmock = mock(:gemmock)
|
111
|
+
spec1 = mock(:spec)
|
112
|
+
spec2 = mock(:spec)
|
113
|
+
gemmock.should_receive(:find_name).at_least(1).times.and_return([spec1, spec2])
|
114
|
+
Gem.should_receive(:source_index).at_least(1).times.and_return(gemmock)
|
115
|
+
spec1.stub!(:full_name).and_return('gem1-1.0.0')
|
116
|
+
spec1.stub!(:name).and_return('gem1')
|
117
|
+
spec1.stub!(:version).and_return('1.0.0')
|
118
|
+
spec2.stub!(:full_name).and_return('gem2-1.0.0')
|
119
|
+
spec2.stub!(:name).and_return('gem2')
|
120
|
+
spec2.stub!(:version).and_return('1.0.0')
|
121
|
+
Registry.should_receive(:yardoc_file_for_gem).with('gem1', '= 1.0.0').and_return('/path/to/file')
|
122
|
+
Registry.should_receive(:yardoc_file_for_gem).with('gem2', '= 1.0.0').and_return(nil)
|
123
|
+
Registry.should_receive(:load_yardoc).with('/path/to/file')
|
124
|
+
CLI::Gems.should_receive(:run).with('gem2', '1.0.0').and_return(nil)
|
125
|
+
Dir.stub!(:chdir)
|
126
|
+
@diff.run('gem1-1.0.0.gem', 'gem2-1.0.0')
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should search for .gem file" do
|
130
|
+
iomock = mock(:io)
|
131
|
+
File.should_receive(:directory?).with('gem1/.yardoc').and_return(false)
|
132
|
+
File.should_receive(:directory?).with('gem2.gem/.yardoc').and_return(false)
|
133
|
+
File.should_receive(:directory?).with('gem1').and_return(false)
|
134
|
+
File.should_receive(:directory?).with('gem2.gem').and_return(false)
|
135
|
+
File.should_receive(:directory?).any_number_of_times
|
136
|
+
File.should_receive(:exist?).with('gem1.gem').and_return(true)
|
137
|
+
File.should_receive(:exist?).with('gem2.gem').and_return(true)
|
138
|
+
File.should_receive(:open).with('gem1.gem', 'rb').and_yield(iomock)
|
139
|
+
File.should_receive(:open).with('gem2.gem', 'rb')
|
140
|
+
FileUtils.should_receive(:mkdir_p)
|
141
|
+
Gem::Package.should_receive(:open).with(iomock)
|
142
|
+
FileUtils.should_receive(:rm_rf)
|
143
|
+
@diff.run('gem1', 'gem2.gem')
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should search for .gem file on rubygems.org" do
|
147
|
+
iomock = mock(:io)
|
148
|
+
File.should_receive(:directory?).with('gem1/.yardoc').and_return(false)
|
149
|
+
File.should_receive(:directory?).with('gem2.gem/.yardoc').and_return(false)
|
150
|
+
File.should_receive(:directory?).with('gem1').and_return(false)
|
151
|
+
File.should_receive(:directory?).with('gem2.gem').and_return(false)
|
152
|
+
File.should_receive(:directory?).any_number_of_times
|
153
|
+
File.should_receive(:exist?).with('gem1.gem').and_return(false)
|
154
|
+
File.should_receive(:exist?).with('gem2.gem').and_return(false)
|
155
|
+
@diff.should_receive(:open).with('http://rubygems.org/downloads/gem1.gem').and_yield(iomock)
|
156
|
+
@diff.should_receive(:open).with('http://rubygems.org/downloads/gem2.gem')
|
157
|
+
FileUtils.should_receive(:mkdir_p)
|
158
|
+
Gem::Package.should_receive(:open).with(iomock)
|
159
|
+
FileUtils.should_receive(:rm_rf)
|
160
|
+
@diff.run('gem1', 'gem2.gem')
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should error if gem is not found" do
|
164
|
+
log.should_receive(:error).with("Cannot find gem gem1")
|
165
|
+
log.should_receive(:error).with("Cannot find gem gem2.gem")
|
166
|
+
@diff.stub!(:load_gem_data).and_return(false)
|
167
|
+
@diff.run('gem1', 'gem2.gem')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CLI::Help do
|
4
|
+
describe '#run' do
|
5
|
+
it "should accept 'help command'" do
|
6
|
+
CLI::Yardoc.should_receive(:run).with('--help')
|
7
|
+
CLI::Help.run('doc')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept no arguments (lists all commands)" do
|
11
|
+
CLI::CommandParser.should_receive(:run).with('--help')
|
12
|
+
CLI::Help.run
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should show all commands if command isn't found" do
|
16
|
+
CLI::CommandParser.should_receive(:run).with('--help')
|
17
|
+
help = CLI::Help.new
|
18
|
+
help.should_receive(:puts).with(/not found/)
|
19
|
+
help.run('unknown')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CLI::Server do
|
4
|
+
before do
|
5
|
+
@no_verify_libraries = false
|
6
|
+
@libraries = {}
|
7
|
+
@options = {:single_library => true, :caching => false}
|
8
|
+
@server_options = {:Port => 8808}
|
9
|
+
@adapter = mock(:adapter)
|
10
|
+
@cli = YARD::CLI::Server.new
|
11
|
+
@cli.stub!(:adapter).and_return(@adapter)
|
12
|
+
end
|
13
|
+
|
14
|
+
def rack_required
|
15
|
+
begin; require 'rack'; rescue LoadError; pending "rack required for this test" end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(*args)
|
19
|
+
if @libraries.empty?
|
20
|
+
library = Server::LibraryVersion.new(File.basename(Dir.pwd), nil, '.yardoc')
|
21
|
+
@libraries = {library.name => [library]}
|
22
|
+
end
|
23
|
+
unless @no_verify_libraries
|
24
|
+
@libraries.values.each {|libs| libs.each {|lib| File.should_receive(:exist?).at_least(1).times.with(lib.yardoc_file).and_return(true) } }
|
25
|
+
end
|
26
|
+
@adapter.should_receive(:new).with(@libraries, @options, @server_options).and_return(@adapter)
|
27
|
+
@adapter.should_receive(:start)
|
28
|
+
@cli.run(*args.flatten)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should default to current dir if no library is specified" do
|
32
|
+
Dir.should_receive(:pwd).and_return('/path/to/foo')
|
33
|
+
@libraries['foo'] = [Server::LibraryVersion.new('foo', nil, '.yardoc')]
|
34
|
+
run
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should use .yardoc as yardoc file is library list is odd" do
|
38
|
+
@libraries['a'] = [Server::LibraryVersion.new('a', nil,'.yardoc')]
|
39
|
+
run 'a'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should force multi library if more than one library is listed" do
|
43
|
+
@options[:single_library] = false
|
44
|
+
@libraries['a'] = [Server::LibraryVersion.new('a', nil, 'b')]
|
45
|
+
@libraries['c'] = [Server::LibraryVersion.new('c', nil, '.yardoc')]
|
46
|
+
run %w(a b c)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should accept -m, --multi-library" do
|
50
|
+
@options[:single_library] = false
|
51
|
+
run '-m'
|
52
|
+
run '--multi-library'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should accept -c, --cache" do
|
56
|
+
@options[:caching] = true
|
57
|
+
run '-c'
|
58
|
+
run '--cache'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should accept -r, --reload" do
|
62
|
+
@options[:incremental] = true
|
63
|
+
run '-r'
|
64
|
+
run '--reload'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should accept -d, --daemon" do
|
68
|
+
@server_options[:daemonize] = true
|
69
|
+
run '-d'
|
70
|
+
run '--daemon'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should accept -p, --port" do
|
74
|
+
@server_options[:Port] = 10
|
75
|
+
run '-p', '10'
|
76
|
+
run '--port', '10'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should accept --docroot" do
|
80
|
+
@server_options[:DocumentRoot] = '/foo/bar'
|
81
|
+
run '--docroot', '/foo/bar'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should accept -a webrick to create WEBrick adapter" do
|
85
|
+
@cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
|
86
|
+
run '-a', 'webrick'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should accept -a rack to create Rack adapter" do
|
90
|
+
rack_required
|
91
|
+
@cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
|
92
|
+
run '-a', 'rack'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should default to Rack adapter if exists on system" do
|
96
|
+
rack_required
|
97
|
+
@cli.unstub(:adapter)
|
98
|
+
@cli.should_receive(:require).with('rubygems').and_return(false)
|
99
|
+
@cli.should_receive(:require).with('rack').and_return(true)
|
100
|
+
@cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
|
101
|
+
@cli.send(:select_adapter)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should fall back to WEBrick adapter if Rack is not on system" do
|
105
|
+
@cli.unstub(:adapter)
|
106
|
+
@cli.should_receive(:require).with('rubygems').and_return(false)
|
107
|
+
@cli.should_receive(:require).with('rack').and_raise(LoadError)
|
108
|
+
@cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
|
109
|
+
@cli.send(:select_adapter)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should accept -s, --server" do
|
113
|
+
@server_options[:server] = 'thin'
|
114
|
+
run '-s', 'thin'
|
115
|
+
run '--server', 'thin'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should accept -g, --gems" do
|
119
|
+
@no_verify_libraries = true
|
120
|
+
@options[:single_library] = false
|
121
|
+
@libraries['gem1'] = [Server::LibraryVersion.new('gem1', '1.0.0', nil, :gem)]
|
122
|
+
@libraries['gem2'] = [Server::LibraryVersion.new('gem2', '1.0.0', nil, :gem)]
|
123
|
+
gem1 = mock(:gem1)
|
124
|
+
gem1.stub!(:name).and_return('gem1')
|
125
|
+
gem1.stub!(:version).and_return('1.0.0')
|
126
|
+
gem1.stub!(:full_gem_path).and_return('/path/to/foo')
|
127
|
+
gem2 = mock(:gem2)
|
128
|
+
gem2.stub!(:name).and_return('gem2')
|
129
|
+
gem2.stub!(:version).and_return('1.0.0')
|
130
|
+
gem2.stub!(:full_gem_path).and_return('/path/to/bar')
|
131
|
+
specs = {'gem1' => gem1, 'gem2' => gem2}
|
132
|
+
source = mock(:source_index)
|
133
|
+
source.stub!(:find_name).and_return do |k, ver|
|
134
|
+
k == '' ? specs.values : specs.grep(k).map {|name| specs[name] }
|
135
|
+
end
|
136
|
+
Gem.stub!(:source_index).and_return(source)
|
137
|
+
run '-g'
|
138
|
+
run '--gems'
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe YARD::CLI::Stats do
|
5
|
+
before do
|
6
|
+
Registry.clear
|
7
|
+
YARD.parse_string <<-eof
|
8
|
+
class A
|
9
|
+
CONST = 1
|
10
|
+
|
11
|
+
def foo; end
|
12
|
+
|
13
|
+
# Documented
|
14
|
+
def bar; end
|
15
|
+
end
|
16
|
+
module B; end
|
17
|
+
eof
|
18
|
+
|
19
|
+
@main_stats =
|
20
|
+
"Files: 1\n" +
|
21
|
+
"Modules: 1 ( 1 undocumented)\n" +
|
22
|
+
"Classes: 1 ( 1 undocumented)\n" +
|
23
|
+
"Constants: 1 ( 1 undocumented)\n" +
|
24
|
+
"Methods: 2 ( 1 undocumented)\n" +
|
25
|
+
" 20.00% documented\n"
|
26
|
+
|
27
|
+
@output = StringIO.new
|
28
|
+
@stats = CLI::Stats.new(false)
|
29
|
+
@stats.stub!(:support_rdoc_document_file!).and_return([])
|
30
|
+
@stats.stub!(:yardopts).and_return([])
|
31
|
+
@stats.stub!(:puts).with {|*args| @output << args.join("\n") << "\n" }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should list undocumented objects with --list-undoc" do
|
35
|
+
@stats.run('--list-undoc')
|
36
|
+
@output.string.should == <<-eof
|
37
|
+
#{@main_stats}
|
38
|
+
Undocumented Objects:
|
39
|
+
|
40
|
+
(in file: (stdin))
|
41
|
+
B
|
42
|
+
A
|
43
|
+
A::CONST
|
44
|
+
A#foo
|
45
|
+
eof
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should list undocumented objects in compact mode with --list-undoc --compact" do
|
49
|
+
@stats.run('--list-undoc', '--compact')
|
50
|
+
@output.string.should == <<-eof
|
51
|
+
#{@main_stats}
|
52
|
+
Undocumented Objects:
|
53
|
+
B ((stdin))
|
54
|
+
A ((stdin))
|
55
|
+
A::CONST ((stdin))
|
56
|
+
A#foo ((stdin))
|
57
|
+
eof
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should still list stats with --quiet" do
|
61
|
+
@stats.run('--quiet')
|
62
|
+
@output.string.should == @main_stats
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not include public methods in stats with --no-public" do
|
66
|
+
@stats.run('--no-public')
|
67
|
+
@output.string.should ==
|
68
|
+
"Files: 1\n" +
|
69
|
+
"Modules: 1 ( 1 undocumented)\n" +
|
70
|
+
"Classes: 1 ( 1 undocumented)\n" +
|
71
|
+
"Constants: 1 ( 1 undocumented)\n" +
|
72
|
+
"Methods: 0 ( 0 undocumented)\n" +
|
73
|
+
" 0.00% documented\n"
|
74
|
+
end
|
75
|
+
end
|
data/spec/cli/yardoc_spec.rb
CHANGED
@@ -1,214 +1,470 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
class YARD::CLI::Yardoc; public :optparse end
|
4
|
-
|
5
3
|
describe YARD::CLI::Yardoc do
|
6
4
|
before do
|
7
5
|
@yardoc = YARD::CLI::Yardoc.new
|
8
|
-
@yardoc.
|
6
|
+
@yardoc.statistics = false
|
7
|
+
@yardoc.use_document_file = false
|
8
|
+
@yardoc.use_yardopts_file = false
|
9
|
+
@yardoc.generate = false
|
9
10
|
Templates::Engine.stub!(:render)
|
10
11
|
Templates::Engine.stub!(:generate)
|
11
12
|
YARD.stub!(:parse)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
describe 'Defaults' do
|
16
|
+
before do
|
17
|
+
@yardoc = CLI::Yardoc.new
|
18
|
+
@yardoc.stub!(:yardopts).and_return([])
|
19
|
+
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
20
|
+
@yardoc.parse_arguments
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use cache by default" do
|
24
|
+
@yardoc.use_cache.should == false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "print statistics by default" do
|
28
|
+
@yardoc.statistics.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should generate output by default" do
|
32
|
+
@yardoc.generate.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should read .yardopts by default" do
|
36
|
+
@yardoc.use_yardopts_file.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should read .document by default" do
|
40
|
+
@yardoc.use_document_file.should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should use lib/**/*.rb and ext/**/*.c as default file glob" do
|
44
|
+
@yardoc.files.should == ['lib/**/*.rb', 'ext/**/*.c']
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should use rdoc as default markup type" do
|
48
|
+
@yardoc.options[:markup].should == :rdoc
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use default as default template" do
|
52
|
+
@yardoc.options[:template].should == :default
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should use HTML as default format" do
|
56
|
+
@yardoc.options[:format].should == :html
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should use 'Object' as default return type" do
|
60
|
+
@yardoc.options[:default_return].should == 'Object'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not hide void return types by default" do
|
64
|
+
@yardoc.options[:hide_void_return].should == false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should only show public visibility by default" do
|
68
|
+
@yardoc.visibilities.should == [:public]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not list objects by default" do
|
72
|
+
@yardoc.list.should == false
|
73
|
+
end
|
17
74
|
end
|
75
|
+
|
76
|
+
describe 'General options' do
|
77
|
+
def self.should_accept(*args, &block)
|
78
|
+
@counter ||= 0
|
79
|
+
@counter += 1
|
80
|
+
counter = @counter
|
81
|
+
args.each do |arg|
|
82
|
+
define_method("test_options_#{@counter}", &block)
|
83
|
+
it("should accept #{arg}") { send("test_options_#{counter}", arg) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
should_accept('-c', '--use-cache') do |arg|
|
88
|
+
@yardoc.parse_arguments(arg)
|
89
|
+
@yardoc.use_cache.should == true
|
90
|
+
end
|
91
|
+
|
92
|
+
should_accept('--no-cache') do |arg|
|
93
|
+
@yardoc.parse_arguments(arg)
|
94
|
+
@yardoc.use_cache.should == false
|
95
|
+
end
|
96
|
+
|
97
|
+
should_accept('--yardopts') do |arg|
|
98
|
+
@yardoc = CLI::Yardoc.new
|
99
|
+
@yardoc.use_document_file = false
|
100
|
+
@yardoc.should_receive(:yardopts).and_return([])
|
101
|
+
@yardoc.parse_arguments('--no-yardopts', arg)
|
102
|
+
@yardoc.use_yardopts_file.should == true
|
103
|
+
end
|
18
104
|
|
19
|
-
|
20
|
-
|
105
|
+
should_accept('--no-yardopts') do |arg|
|
106
|
+
@yardoc = CLI::Yardoc.new
|
107
|
+
@yardoc.use_document_file = false
|
108
|
+
@yardoc.should_not_receive(:yardopts)
|
109
|
+
@yardoc.parse_arguments('--yardopts', arg)
|
110
|
+
@yardoc.use_yardopts_file.should == false
|
111
|
+
end
|
21
112
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@yardoc.optparse("--markup-provider", "test2")
|
30
|
-
@yardoc.options[:markup_provider].should == :test2
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should search for and use yardopts file specified by #options_file" do
|
34
|
-
File.should_receive(:read_binary).with("test").and_return("-o \n\nMYPATH\nFILE1 FILE2")
|
35
|
-
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
36
|
-
@yardoc.options_file = "test"
|
37
|
-
@yardoc.run
|
38
|
-
@yardoc.options[:serializer].options[:basepath].should == "MYPATH"
|
39
|
-
@yardoc.files.should == ["FILE1", "FILE2"]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should setup visibility rules as verifier" do
|
43
|
-
methobj = CodeObjects::MethodObject.new(:root, :test) {|o| o.visibility = :private }
|
44
|
-
File.should_receive(:read_binary).with("test").and_return("--private")
|
45
|
-
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
46
|
-
@yardoc.options_file = "test"
|
47
|
-
@yardoc.run
|
48
|
-
@yardoc.options[:verifier].call(methobj).should be_true
|
49
|
-
end
|
113
|
+
should_accept('--document') do |arg|
|
114
|
+
@yardoc = CLI::Yardoc.new
|
115
|
+
@yardoc.use_yardopts_file = false
|
116
|
+
@yardoc.should_receive(:support_rdoc_document_file!).and_return([])
|
117
|
+
@yardoc.parse_arguments('--no-document', arg)
|
118
|
+
@yardoc.use_document_file.should == true
|
119
|
+
end
|
50
120
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@yardoc.options[:serializer].options[:basepath].should == "MYPATH"
|
81
|
-
@yardoc.files.should == ["FILE2", "FILE3", "FILE1"]
|
121
|
+
should_accept('--no-document') do |arg|
|
122
|
+
@yardoc = CLI::Yardoc.new
|
123
|
+
@yardoc.use_yardopts_file = false
|
124
|
+
@yardoc.should_not_receive(:support_rdoc_document_file!)
|
125
|
+
@yardoc.parse_arguments('--document', arg)
|
126
|
+
@yardoc.use_document_file.should == false
|
127
|
+
end
|
128
|
+
|
129
|
+
should_accept('-b', '--db') do |arg|
|
130
|
+
@yardoc.parse_arguments(arg, 'test')
|
131
|
+
Registry.yardoc_file.should == 'test'
|
132
|
+
Registry.yardoc_file = '.yardoc'
|
133
|
+
end
|
134
|
+
|
135
|
+
should_accept('-n', '--no-output') do |arg|
|
136
|
+
Templates::Engine.should_not_receive(:generate)
|
137
|
+
@yardoc.run(arg)
|
138
|
+
end
|
139
|
+
|
140
|
+
should_accept('--exclude') do |arg|
|
141
|
+
YARD.should_receive(:parse).with(['a'], ['nota', 'b'])
|
142
|
+
@yardoc.run(arg, 'nota', arg, 'b', 'a')
|
143
|
+
end
|
144
|
+
|
145
|
+
should_accept('--no-save') do |arg|
|
146
|
+
YARD.should_receive(:parse)
|
147
|
+
Registry.should_not_receive(:save)
|
148
|
+
@yardoc.run(arg)
|
149
|
+
end
|
82
150
|
end
|
83
151
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@yardoc.options[:files].should == %w( extra_file1 extra_file2 )
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should accept files section only containing extra files" do
|
93
|
-
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
94
|
-
@yardoc.stub!(:yardopts).and_return([])
|
95
|
-
@yardoc.parse_arguments *%w( - LICENSE )
|
96
|
-
@yardoc.files.should == %w( lib/**/*.rb ext/**/*.c )
|
97
|
-
@yardoc.options[:files].should == %w( LICENSE )
|
98
|
-
end
|
152
|
+
describe 'Output options' do
|
153
|
+
it "should accept --title" do
|
154
|
+
@yardoc.parse_arguments('--title', 'hello world')
|
155
|
+
@yardoc.options[:title].should == 'hello world'
|
156
|
+
end
|
99
157
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
obj.stub!(:namespace).and_return(ns)
|
157
|
-
obj.should_receive(:tag).ordered.with(:private).and_return(false)
|
158
|
-
@yardoc.optparse *%w( --no-private )
|
159
|
-
@yardoc.options[:verifier].call(obj).should == true
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should hide methods inside a 'private' class/module with --no-private" do
|
163
|
-
Registry.clear
|
164
|
-
YARD.parse_string <<-eof
|
165
|
-
# @private
|
166
|
-
class A
|
167
|
-
def foo; end
|
158
|
+
it "should allow --title to have multiple spaces in .yardopts" do
|
159
|
+
File.should_receive(:read_binary).with("test").and_return("--title \"Foo Bar\"")
|
160
|
+
@yardoc.options_file = "test"
|
161
|
+
@yardoc.use_yardopts_file = true
|
162
|
+
@yardoc.run
|
163
|
+
@yardoc.options[:title].should == "Foo Bar"
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should alias --main to the --readme flag" do
|
167
|
+
readme = File.join(File.dirname(__FILE__),'..','..','README.md')
|
168
|
+
|
169
|
+
@yardoc.parse_arguments('--main', readme)
|
170
|
+
@yardoc.options[:readme].should == readme
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should select a markup provider when --markup-provider or -mp is set" do
|
174
|
+
@yardoc.parse_arguments("-M", "test")
|
175
|
+
@yardoc.options[:markup_provider].should == :test
|
176
|
+
@yardoc.parse_arguments("--markup-provider", "test2")
|
177
|
+
@yardoc.options[:markup_provider].should == :test2
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should accept --default-return" do
|
181
|
+
@yardoc.parse_arguments *%w( --default-return XYZ )
|
182
|
+
@yardoc.options[:default_return].should == "XYZ"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should allow --hide-void-return to be set" do
|
186
|
+
@yardoc.parse_arguments *%w( --hide-void-return )
|
187
|
+
@yardoc.options[:hide_void_return].should be_true
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should generate all objects with --use-cache" do
|
191
|
+
YARD.should_receive(:parse)
|
192
|
+
Registry.should_receive(:load)
|
193
|
+
Registry.should_receive(:load_all)
|
194
|
+
@yardoc.stub!(:generate).and_return(true)
|
195
|
+
@yardoc.run *%w( --use-cache )
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should not print statistics with --no-stats" do
|
199
|
+
@yardoc.stub!(:statistics).and_return(false)
|
200
|
+
CLI::Stats.should_not_receive(:new)
|
201
|
+
@yardoc.run *%w( --no-stats )
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '--asset' do
|
205
|
+
before do
|
206
|
+
@yardoc.generate = true
|
207
|
+
@yardoc.stub!(:run_generate)
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should copy assets to output directory" do
|
211
|
+
FileUtils.should_receive(:cp_r).with('a', 'doc/a')
|
212
|
+
@yardoc.run *%w( --asset a )
|
213
|
+
@yardoc.assets.should == {'a' => 'a'}
|
168
214
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
215
|
+
|
216
|
+
it "should allow multiple --asset options" do
|
217
|
+
FileUtils.should_receive(:cp_r).with('a', 'doc/a')
|
218
|
+
FileUtils.should_receive(:cp_r).with('b', 'doc/b')
|
219
|
+
@yardoc.run *%w( --asset a --asset b )
|
220
|
+
@yardoc.assets.should == {'a' => 'a', 'b' => 'b'}
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should not allow from or to to refer to a path above current path" do
|
224
|
+
log.should_receive(:warn).exactly(4).times.with(/invalid/i)
|
225
|
+
@yardoc.run *%w( --asset ../../../etc/passwd )
|
226
|
+
@yardoc.assets.should be_empty
|
227
|
+
@yardoc.run *%w( --asset a/b/c/d/../../../../../../etc/passwd )
|
228
|
+
@yardoc.assets.should be_empty
|
229
|
+
@yardoc.run *%w( --asset /etc/passwd )
|
230
|
+
@yardoc.assets.should be_empty
|
231
|
+
@yardoc.run *%w( --asset normal:/etc/passwd )
|
232
|
+
@yardoc.assets.should be_empty
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should allow from:to syntax" do
|
236
|
+
FileUtils.should_receive(:cp_r).with('foo', 'doc/bar')
|
237
|
+
@yardoc.run *%w( --asset foo:bar )
|
238
|
+
@yardoc.assets.should == {'foo' => 'bar'}
|
239
|
+
end
|
240
|
+
end
|
173
241
|
end
|
174
242
|
|
175
|
-
|
176
|
-
|
177
|
-
|
243
|
+
describe '--no-private option' do
|
244
|
+
it "should accept --no-private" do
|
245
|
+
obj = mock(:object)
|
246
|
+
obj.should_receive(:tag).ordered.with(:private).and_return(true)
|
247
|
+
@yardoc.parse_arguments *%w( --no-private )
|
248
|
+
@yardoc.options[:verifier].call(obj).should == false
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should hide object if namespace is @private with --no-private" do
|
252
|
+
ns = mock(:namespace)
|
253
|
+
ns.stub!(:type).and_return(:module)
|
254
|
+
ns.should_receive(:tag).ordered.with(:private).and_return(true)
|
255
|
+
obj = mock(:object)
|
256
|
+
obj.stub!(:namespace).and_return(ns)
|
257
|
+
obj.should_receive(:tag).ordered.with(:private).and_return(false)
|
258
|
+
@yardoc.parse_arguments *%w( --no-private )
|
259
|
+
@yardoc.options[:verifier].call(obj).should == false
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should not call #tag on namespace if namespace is proxy with --no-private" do
|
263
|
+
ns = mock(:namespace)
|
264
|
+
ns.stub!(:type).and_return(:proxy)
|
265
|
+
ns.should_not_receive(:tag)
|
266
|
+
obj = mock(:object)
|
267
|
+
obj.stub!(:type).and_return(:class)
|
268
|
+
obj.stub!(:namespace).and_return(ns)
|
269
|
+
obj.stub!(:visibility).and_return(:public)
|
270
|
+
obj.should_receive(:tag).ordered.with(:private).and_return(false)
|
271
|
+
@yardoc.parse_arguments *%w( --no-private )
|
272
|
+
@yardoc.options[:verifier].call(obj).should == true
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should hide methods inside a 'private' class/module with --no-private" do
|
276
|
+
Registry.clear
|
277
|
+
YARD.parse_string <<-eof
|
278
|
+
# @private
|
279
|
+
class ABC
|
280
|
+
def foo; end
|
281
|
+
end
|
282
|
+
eof
|
283
|
+
@yardoc.parse_arguments *%w( --no-private )
|
284
|
+
@yardoc.options[:verifier].call(Registry.at('ABC')).should be_false
|
285
|
+
@yardoc.options[:verifier].call(Registry.at('ABC#foo')).should be_false
|
286
|
+
end
|
178
287
|
end
|
179
288
|
|
180
|
-
|
181
|
-
|
182
|
-
|
289
|
+
describe '.yardopts and .document handling' do
|
290
|
+
before do
|
291
|
+
@yardoc.use_yardopts_file = true
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should search for and use yardopts file specified by #options_file" do
|
295
|
+
File.should_receive(:read_binary).with("test").and_return("-o \n\nMYPATH\nFILE1 FILE2")
|
296
|
+
@yardoc.use_document_file = false
|
297
|
+
@yardoc.options_file = "test"
|
298
|
+
@yardoc.run
|
299
|
+
@yardoc.options[:serializer].options[:basepath].should == "MYPATH"
|
300
|
+
@yardoc.files.should == ["FILE1", "FILE2"]
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should use String#shell_split to split .yardopts tokens" do
|
304
|
+
optsdata = "foo bar"
|
305
|
+
optsdata.should_receive(:shell_split)
|
306
|
+
File.should_receive(:read_binary).with("test").and_return(optsdata)
|
307
|
+
@yardoc.options_file = "test"
|
308
|
+
@yardoc.run
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should allow opts specified in command line to override yardopts file" do
|
312
|
+
File.should_receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
|
313
|
+
@yardoc.run("-o", "MYPATH", "FILE")
|
314
|
+
@yardoc.options[:serializer].options[:basepath].should == "MYPATH"
|
315
|
+
@yardoc.files.should == ["FILE"]
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should load the RDoc .document file if found" do
|
319
|
+
File.should_receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
|
320
|
+
@yardoc.use_document_file = true
|
321
|
+
@yardoc.stub!(:support_rdoc_document_file!).and_return(["FILE2", "FILE3"])
|
322
|
+
@yardoc.run("-o", "MYPATH", "FILE1")
|
323
|
+
@yardoc.options[:serializer].options[:basepath].should == "MYPATH"
|
324
|
+
@yardoc.files.should == ["FILE2", "FILE3", "FILE1"]
|
325
|
+
end
|
183
326
|
end
|
184
327
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
328
|
+
describe 'Query options' do
|
329
|
+
before do
|
330
|
+
Registry.clear
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should setup visibility rules as verifier" do
|
334
|
+
methobj = CodeObjects::MethodObject.new(:root, :test) {|o| o.visibility = :private }
|
335
|
+
File.should_receive(:read_binary).with("test").and_return("--private")
|
336
|
+
@yardoc.use_yardopts_file = true
|
337
|
+
@yardoc.options_file = "test"
|
338
|
+
@yardoc.run
|
339
|
+
@yardoc.options[:verifier].call(methobj).should be_true
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should accept a --query" do
|
343
|
+
@yardoc.parse_arguments *%w( --query @return )
|
344
|
+
@yardoc.options[:verifier].should be_a(Verifier)
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should accept multiple --query arguments" do
|
348
|
+
obj = mock(:object)
|
349
|
+
obj.should_receive(:tag).ordered.with('return').and_return(true)
|
350
|
+
obj.should_receive(:tag).ordered.with('tag').and_return(false)
|
351
|
+
@yardoc.parse_arguments *%w( --query @return --query @tag )
|
352
|
+
@yardoc.options[:verifier].should be_a(Verifier)
|
353
|
+
@yardoc.options[:verifier].call(obj).should == false
|
354
|
+
end
|
191
355
|
end
|
192
356
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
357
|
+
describe 'Extra file arguments' do
|
358
|
+
it "should accept extra files if specified after '-' with source files" do
|
359
|
+
File.should_receive(:file?).with('extra_file1').and_return(true)
|
360
|
+
File.should_receive(:file?).with('extra_file2').and_return(true)
|
361
|
+
@yardoc.parse_arguments *%w( file1 file2 - extra_file1 extra_file2 )
|
362
|
+
@yardoc.files.should == %w( file1 file2 )
|
363
|
+
@yardoc.options[:files].should == %w( extra_file1 extra_file2 )
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should accept files section only containing extra files" do
|
367
|
+
@yardoc.parse_arguments *%w( - LICENSE )
|
368
|
+
@yardoc.files.should == %w( lib/**/*.rb ext/**/*.c )
|
369
|
+
@yardoc.options[:files].should == %w( LICENSE )
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should accept globs as extra files" do
|
373
|
+
Dir.should_receive(:glob).with('README*').and_return []
|
374
|
+
Dir.should_receive(:glob).with('*.txt').and_return ['a.txt', 'b.txt']
|
375
|
+
File.should_receive(:file?).with('a.txt').and_return(true)
|
376
|
+
File.should_receive(:file?).with('b.txt').and_return(true)
|
377
|
+
@yardoc.parse_arguments *%w( file1 file2 - *.txt )
|
378
|
+
@yardoc.files.should == %w( file1 file2 )
|
379
|
+
@yardoc.options[:files].should == %w( a.txt b.txt )
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should warn if extra file is not found" do
|
383
|
+
log.should_receive(:warn).with(/Could not find extra file: UNKNOWN/)
|
384
|
+
@yardoc.parse_arguments *%w( - UNKNOWN )
|
385
|
+
end
|
386
|
+
|
387
|
+
it "should warn if readme file is not found" do
|
388
|
+
log.should_receive(:warn).with(/Could not find readme file: UNKNOWN/)
|
389
|
+
@yardoc.parse_arguments *%w( -r UNKNOWN )
|
390
|
+
end
|
203
391
|
end
|
204
392
|
|
205
|
-
|
206
|
-
|
207
|
-
|
393
|
+
describe 'Source file arguments' do
|
394
|
+
it "should accept no params and parse lib/**/*.rb ext/**/*.c" do
|
395
|
+
@yardoc.parse_arguments
|
396
|
+
@yardoc.files.should == %w( lib/**/*.rb ext/**/*.c )
|
397
|
+
end
|
208
398
|
end
|
209
399
|
|
210
|
-
|
211
|
-
|
212
|
-
|
400
|
+
describe 'Tags options' do
|
401
|
+
def tag_created(switch, factory_method)
|
402
|
+
visible_tags = mock(:visible_tags)
|
403
|
+
visible_tags.should_receive(:|).ordered.with([:foo])
|
404
|
+
visible_tags.should_receive(:-).ordered.with([]).and_return(visible_tags)
|
405
|
+
Tags::Library.should_receive(:define_tag).with(nil, :foo, factory_method)
|
406
|
+
Tags::Library.stub!(:visible_tags=)
|
407
|
+
Tags::Library.should_receive(:visible_tags).at_least(1).times.and_return(visible_tags)
|
408
|
+
@yardoc.parse_arguments("--#{switch}-tag", 'foo')
|
409
|
+
end
|
410
|
+
|
411
|
+
def tag_hidden(tag)
|
412
|
+
visible_tags = mock(:visible_tags)
|
413
|
+
visible_tags.should_receive(:|).ordered.with([tag])
|
414
|
+
visible_tags.should_receive(:-).ordered.with([tag]).and_return([])
|
415
|
+
Tags::Library.should_receive(:define_tag).with(nil, tag, nil)
|
416
|
+
Tags::Library.stub!(:visible_tags=)
|
417
|
+
Tags::Library.should_receive(:visible_tags).at_least(1).times.and_return(visible_tags)
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should accept --tag" do
|
421
|
+
Tags::Library.should_receive(:define_tag).with('Title of Foo', :foo, nil)
|
422
|
+
@yardoc.parse_arguments('--tag', 'foo:Title of Foo')
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should accept --tag without title" do
|
426
|
+
Tags::Library.should_receive(:define_tag).with(nil, :foo, nil)
|
427
|
+
@yardoc.parse_arguments('--tag', 'foo')
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should only list tag once if declared twice" do
|
431
|
+
visible_tags = []
|
432
|
+
Tags::Library.stub!(:define_tag)
|
433
|
+
Tags::Library.stub!(:visible_tags).and_return([:foo])
|
434
|
+
Tags::Library.stub!(:visible_tags=).with {|value| visible_tags = value }
|
435
|
+
@yardoc.parse_arguments('--tag', 'foo', '--tag', 'foo')
|
436
|
+
visible_tags.should == [:foo]
|
437
|
+
end
|
438
|
+
|
439
|
+
it "should accept --type-tag" do
|
440
|
+
tag_created 'type', :with_types
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should accept --type-name-tag" do
|
444
|
+
tag_created 'type-name', :with_types_and_name
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should accept --name-tag" do
|
448
|
+
tag_created 'name', :with_name
|
449
|
+
end
|
450
|
+
|
451
|
+
it "should accept --title-tag" do
|
452
|
+
tag_created 'title', :with_title_and_text
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should accept --hide-tag before tag is listed" do
|
456
|
+
tag_hidden(:anewfoo)
|
457
|
+
@yardoc.parse_arguments('--hide-tag', 'anewfoo', '--tag', 'anewfoo')
|
458
|
+
end
|
459
|
+
|
460
|
+
it "should accept --hide-tag after tag is listed" do
|
461
|
+
tag_hidden(:anewfoo2)
|
462
|
+
@yardoc.parse_arguments('--tag', 'anewfoo2', '--hide-tag', 'anewfoo2')
|
463
|
+
end
|
464
|
+
|
465
|
+
it "should accept --transitive-tag" do
|
466
|
+
@yardoc.parse_arguments('--transitive-tag', 'foo')
|
467
|
+
Tags::Library.transitive_tags.should include(:foo)
|
468
|
+
end
|
213
469
|
end
|
214
470
|
end
|