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,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Server::Adapter do
|
4
|
+
after(:all) { Server::Adapter.shutdown }
|
5
|
+
|
6
|
+
describe '#add_library' do
|
7
|
+
it "should add a library" do
|
8
|
+
lib = LibraryVersion.new('yard')
|
9
|
+
a = Adapter.new({})
|
10
|
+
a.libraries.should be_empty
|
11
|
+
a.add_library(lib)
|
12
|
+
a.libraries['yard'].should == [lib]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#start' do
|
17
|
+
it "should not implement #start" do
|
18
|
+
lambda { Adapter.new({}).start }.should raise_error(NotImplementedError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.setup' do
|
23
|
+
it 'should add template paths and helpers' do
|
24
|
+
Adapter.setup
|
25
|
+
Templates::Template.extra_includes.should include(DocServerHelper)
|
26
|
+
Templates::Engine.template_paths.should include(YARD::ROOT + '/yard/server/templates')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.shutdown' do
|
31
|
+
it 'should cleanup template paths and helpers' do
|
32
|
+
Adapter.setup
|
33
|
+
Adapter.shutdown
|
34
|
+
Templates::Template.extra_includes.should_not include(DocServerHelper)
|
35
|
+
Templates::Engine.template_paths.should_not include(YARD::ROOT + '/yard/server/templates')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class MyProcCommand < Base
|
4
|
+
def initialize(&block) self.class.send(:define_method, :run, &block) end
|
5
|
+
end
|
6
|
+
|
7
|
+
class MyCacheCommand < Base
|
8
|
+
def run; cache 'foo' end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe YARD::Server::Commands::Base do
|
12
|
+
describe '#cache' do
|
13
|
+
before do
|
14
|
+
@command = MyCacheCommand.new(:adapter => mock_adapter, :caching => true)
|
15
|
+
@command.request = OpenStruct.new
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not cache if caching == false" do
|
19
|
+
File.should_not_receive(:open)
|
20
|
+
@command.caching = false
|
21
|
+
@command.run
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should require document root to cache" do
|
25
|
+
File.should_not_receive(:open)
|
26
|
+
@command.adapter.document_root = nil
|
27
|
+
@command.run
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should cache to path/to/file.html and create directories" do
|
31
|
+
FileUtils.should_receive(:mkdir_p).with('/public/path/to')
|
32
|
+
File.should_receive(:open).with('/public/path/to/file.html', anything)
|
33
|
+
@command.request.path = '/path/to/file.html'
|
34
|
+
@command.run
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#redirect' do
|
39
|
+
it "should return a valid redirection" do
|
40
|
+
cmd = MyProcCommand.new { redirect '/foo' }
|
41
|
+
cmd.call(mock_request('/foo')).should ==
|
42
|
+
[302, {"Content-Type" => "text/html", "Location" => "/foo"}, [""]]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#call' do
|
47
|
+
it "should handle a NotFoundError and use message as body" do
|
48
|
+
cmd = MyProcCommand.new { raise NotFoundError, "hello world" }
|
49
|
+
s, h, b = *cmd.call(mock_request('/foo'))
|
50
|
+
s.should == 404
|
51
|
+
b.should == ["hello world"]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not use message as body if not provided in NotFoundError" do
|
55
|
+
cmd = MyProcCommand.new { raise NotFoundError }
|
56
|
+
s, h, b = *cmd.call(mock_request('/foo'))
|
57
|
+
s.should == 404
|
58
|
+
b.should == ["Not found: /foo"]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should handle 404 status code from #run" do
|
62
|
+
cmd = MyProcCommand.new { self.status = 404 }
|
63
|
+
s, h, b = *cmd.call(mock_request('/foo'))
|
64
|
+
s.should == 404
|
65
|
+
b.should == ["Not found: /foo"]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not override body if status is 404 and body is defined" do
|
69
|
+
cmd = MyProcCommand.new { self.body = "foo"; self.status = 404 }
|
70
|
+
s, h, b = *cmd.call(mock_request('/bar'))
|
71
|
+
s.should == 404
|
72
|
+
b.should == ['foo']
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should handle body as Array" do
|
76
|
+
cmd = MyProcCommand.new { self.body = ['a', 'b', 'c'] }
|
77
|
+
s, h, b = *cmd.call(mock_request('/foo'))
|
78
|
+
b.should == %w(a b c)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should allow headers to be defined" do
|
82
|
+
cmd = MyProcCommand.new { self.headers['Foo'] = 'BAR' }
|
83
|
+
s, h, b = *cmd.call(mock_request('/foo'))
|
84
|
+
h['Foo'].should == 'BAR'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Server::Commands::StaticFileCommand do
|
4
|
+
before do
|
5
|
+
adapter = mock_adapter
|
6
|
+
adapter.document_root = '/c'
|
7
|
+
@cmd = StaticFileCommand.new(:adapter => adapter)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#run' do
|
11
|
+
def run(path, status = nil, body = nil)
|
12
|
+
s, h, b = *@cmd.call(mock_request(path))
|
13
|
+
body.should == b.first if body
|
14
|
+
status.should == s if status
|
15
|
+
[s, h, b]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should search through document root before static paths" do
|
19
|
+
File.should_receive(:exist?).with('/c/path/to/file.txt').ordered.and_return(false)
|
20
|
+
StaticFileCommand::STATIC_PATHS.each do |path|
|
21
|
+
File.should_receive(:exist?).with(File.join(path, 'path/to/file.txt')).ordered.and_return(false)
|
22
|
+
end
|
23
|
+
run '/path/to/file.txt'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return file contents if found" do
|
27
|
+
path = File.join(StaticFileCommand::STATIC_PATHS[0], '/path/to/file.txt')
|
28
|
+
File.should_receive(:exist?).with('/c/path/to/file.txt').and_return(false)
|
29
|
+
File.should_receive(:exist?).with(path).and_return(true)
|
30
|
+
File.should_receive(:read).with(path).and_return('FOO')
|
31
|
+
run('/path/to/file.txt', 200, 'FOO')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return 404 if not found" do
|
35
|
+
File.should_receive(:exist?).with('/c/path/to/file.txt').ordered.and_return(false)
|
36
|
+
StaticFileCommand::STATIC_PATHS.each do |path|
|
37
|
+
File.should_receive(:exist?).with(File.join(path, 'path/to/file.txt')).ordered.and_return(false)
|
38
|
+
end
|
39
|
+
run('/path/to/file.txt', 404)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return text/html for file with no extension" do
|
43
|
+
File.should_receive(:exist?).with('/c/file').and_return(true)
|
44
|
+
File.should_receive(:read).with('/c/file')
|
45
|
+
s, h, b = *run('/file')
|
46
|
+
h['Content-Type'].should == 'text/html'
|
47
|
+
end
|
48
|
+
|
49
|
+
{
|
50
|
+
"js" => "text/javascript",
|
51
|
+
"css" => "text/css",
|
52
|
+
"png" => "image/png",
|
53
|
+
"gif" => "image/gif",
|
54
|
+
"htm" => "text/html",
|
55
|
+
"html" => "text/html",
|
56
|
+
"txt" => "text/plain",
|
57
|
+
"unknown" => "application/octet-stream"
|
58
|
+
}.each do |ext, mime|
|
59
|
+
it "should serve file.#{ext} as #{mime}" do
|
60
|
+
File.should_receive(:exist?).with('/c/file.' + ext).and_return(true)
|
61
|
+
File.should_receive(:read).with('/c/file.' + ext)
|
62
|
+
s, h, b = *run('/file.' + ext)
|
63
|
+
h['Content-Type'].should == mime
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class MyDocServerSerializerRouter
|
4
|
+
def docs_prefix; 'PREFIX' end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe YARD::Server::DocServerSerializer do
|
8
|
+
describe '#serialized_path' do
|
9
|
+
before do
|
10
|
+
Registry.clear
|
11
|
+
@command = mock(:command)
|
12
|
+
@command.stub!(:single_library).and_return(false)
|
13
|
+
@command.stub!(:library).and_return(LibraryVersion.new('foo'))
|
14
|
+
@command.stub!(:adapter).and_return(mock_adapter(:router => MyDocServerSerializerRouter.new))
|
15
|
+
@serializer = Server::DocServerSerializer.new(@command)
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) { Server::Adapter.shutdown }
|
19
|
+
|
20
|
+
it "should return '/PREFIX/library/toplevel' for root" do
|
21
|
+
@serializer.serialized_path(Registry.root).should == "/PREFIX/foo/toplevel"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return /PREFIX/library/Object for Object in a library" do
|
25
|
+
@serializer.serialized_path(P('A::B::C')).should == '/PREFIX/foo/A/B/C'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should link to instance method as Class:method" do
|
29
|
+
obj = CodeObjects::MethodObject.new(:root, :method)
|
30
|
+
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel:method'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should link to class method as Class.method" do
|
34
|
+
obj = CodeObjects::MethodObject.new(:root, :method, :class)
|
35
|
+
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel.method'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should link to anchor for constant" do
|
39
|
+
obj = CodeObjects::ConstantObject.new(:root, :FOO)
|
40
|
+
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#FOO-constant'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should link to anchor for class variable" do
|
44
|
+
obj = CodeObjects::ClassVariableObject.new(:root, :@@foo)
|
45
|
+
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#@@foo-classvariable'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not link to /library/ if single_library = true" do
|
49
|
+
@command.stub!(:single_library).and_return(true)
|
50
|
+
@serializer.serialized_path(Registry.root).should == "/PREFIX/toplevel"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return /PREFIX/foo/version if foo has a version" do
|
54
|
+
@command.stub!(:library).and_return(LibraryVersion.new('foo', 'bar'))
|
55
|
+
@serializer.serialized_path(P('A')).should == '/PREFIX/foo/bar/A'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class MyRouterSpecRouter < Router
|
4
|
+
def docs_prefix; 'mydocs/foo' end
|
5
|
+
def list_prefix; 'mylist/foo' end
|
6
|
+
def search_prefix; 'mysearch/foo' end
|
7
|
+
|
8
|
+
def check_static_cache; nil end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe YARD::Server::Router do
|
12
|
+
before do
|
13
|
+
@adapter = mock_adapter
|
14
|
+
@projects = @adapter.libraries['project']
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#parse_library_from_path' do
|
18
|
+
def parse(*args)
|
19
|
+
MyRouterSpecRouter.new(@adapter).parse_library_from_path(args.flatten)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse library and version name out of path" do
|
23
|
+
parse('project', '1.0.0').should == [@projects[0], []]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should parse library and use latest version if version is not supplied" do
|
27
|
+
parse('project').should == [@projects[1], []]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should parse library and use latest version if next component is not a version" do
|
31
|
+
parse('project', 'notaversion').should == [@projects[1], ['notaversion']]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return nil library if no library is found" do
|
35
|
+
parse('notproject').should == [nil, ['notproject']]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not parse library or version if single_library == true" do
|
39
|
+
@adapter.stub!(:options).and_return(:single_library => true)
|
40
|
+
parse('notproject').should == [@projects[0], ['notproject']]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#route' do
|
45
|
+
def route_to(route, command, *args)
|
46
|
+
req = mock_request(route)
|
47
|
+
router = MyRouterSpecRouter.new(@adapter)
|
48
|
+
command.should_receive(:new).and_return do |*args|
|
49
|
+
@command = command.allocate
|
50
|
+
@command.send(:initialize, *args)
|
51
|
+
class << @command; def call(req); self end end
|
52
|
+
@command
|
53
|
+
end
|
54
|
+
router.call(req)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should route /docs/OBJECT to object if single_library = true" do
|
58
|
+
@adapter.stub!(:options).and_return(:single_library => true)
|
59
|
+
route_to('/mydocs/foo/FOO', DisplayObjectCommand)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should route /docs" do
|
63
|
+
route_to('/mydocs/foo', LibraryIndexCommand)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should route /docs as index for library if single_library == true" do
|
67
|
+
@adapter.stub!(:options).and_return(:single_library => true)
|
68
|
+
route_to('/mydocs/foo/', DisplayObjectCommand)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should route /docs/name/version" do
|
72
|
+
route_to('/mydocs/foo/project/1.0.0', DisplayObjectCommand)
|
73
|
+
@command.library.should == @projects[0]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should route /docs/name/ to latest version of library" do
|
77
|
+
route_to('/mydocs/foo/project', DisplayObjectCommand)
|
78
|
+
@command.library.should == @projects[1]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should route /list/name/version/class" do
|
82
|
+
route_to('/mylist/foo/project/1.0.0/class', ListClassesCommand)
|
83
|
+
@command.library.should == @projects[0]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should route /list/name/version/methods" do
|
87
|
+
route_to('/mylist/foo/project/1.0.0/methods', ListMethodsCommand)
|
88
|
+
@command.library.should == @projects[0]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should route /list/name/version/files" do
|
92
|
+
route_to('/mylist/foo/project/1.0.0/files', ListFilesCommand)
|
93
|
+
@command.library.should == @projects[0]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should route /list/name to latest version of library" do
|
97
|
+
route_to('/mylist/foo/project/class', ListClassesCommand)
|
98
|
+
@command.library.should == @projects[1]
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should route /search/name/version" do
|
102
|
+
route_to('/mysearch/foo/project/1.0.0', SearchCommand)
|
103
|
+
@command.library.should == @projects[0]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should route /search/name to latest version of library" do
|
107
|
+
route_to('/mysearch/foo/project', SearchCommand)
|
108
|
+
@command.library.should == @projects[1]
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should search static files for non-existent library" do
|
112
|
+
route_to('/mydocs/foo/notproject', StaticFileCommand)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
include Server
|
5
|
+
include Commands
|
6
|
+
|
7
|
+
def mock_adapter(opts = {})
|
8
|
+
opts[:libraries] ||= {'project' => [LibraryVersion.new('project', '1.0.0'), LibraryVersion.new('project', '1.0.1')]}
|
9
|
+
opts[:document_root] ||= '/public'
|
10
|
+
opts[:options] ||= {:single_library => false, :caching => false}
|
11
|
+
opts[:server_options] ||= {}
|
12
|
+
OpenStruct.new(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_request(path = '/')
|
16
|
+
OpenStruct.new(:path => path)
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Server::StaticCaching do
|
4
|
+
include StaticCaching
|
5
|
+
|
6
|
+
describe '#check_static_cache' do
|
7
|
+
def adapter; @adapter ||= mock_adapter end
|
8
|
+
def request; @request ||= OpenStruct.new end
|
9
|
+
|
10
|
+
it "should return nil if document root is not set" do
|
11
|
+
adapter.document_root = nil
|
12
|
+
check_static_cache.should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should read a file from document root if path matches file on system" do
|
16
|
+
request.path = '/hello/world.html'
|
17
|
+
File.should_receive(:file?).with('/public/hello/world.html').and_return(true)
|
18
|
+
File.should_receive(:open).with('/public/hello/world.html', anything).and_return('body')
|
19
|
+
s, h, b = *check_static_cache
|
20
|
+
s.should == 200
|
21
|
+
b.should == ["body"]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should read a file if path matches file on system + .html" do
|
25
|
+
request.path = '/hello/world'
|
26
|
+
File.should_receive(:file?).with('/public/hello/world.html').and_return(true)
|
27
|
+
File.should_receive(:open).with('/public/hello/world.html', anything).and_return('body')
|
28
|
+
s, h, b = *check_static_cache
|
29
|
+
s.should == 200
|
30
|
+
b.should == ["body"]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return nil if no matching file is found" do
|
34
|
+
request.path = '/hello/foo'
|
35
|
+
File.should_receive(:file?).with('/public/hello/foo.html').and_return(false)
|
36
|
+
check_static_cache.should == nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Server::WebrickServlet do
|
4
|
+
describe '#do_GET' do
|
5
|
+
it "should perform a GET" do
|
6
|
+
resp = OpenStruct.new
|
7
|
+
class << resp
|
8
|
+
def []=(name, value) (self.headers ||= {})[name] = value end
|
9
|
+
end
|
10
|
+
server = mock(:server)
|
11
|
+
server.stub!(:[])
|
12
|
+
adapter = mock_adapter
|
13
|
+
adapter.router = proc { [200, {'Header' => 'foo'}, ['body']]}
|
14
|
+
WebrickServlet.new(server, adapter).do_GET(mock_request('/foo'), resp)
|
15
|
+
resp.status.should == 200
|
16
|
+
resp.headers.should == {'Header' => 'foo'}
|
17
|
+
resp.body.should == 'body'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|