yard 0.8.2.1 → 0.8.3

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.

Files changed (72) hide show
  1. data/ChangeLog +246 -0
  2. data/README.md +12 -2
  3. data/Rakefile +19 -51
  4. data/benchmarks/format_args.rb +3 -3
  5. data/benchmarks/pathname_vs_string.rb +4 -4
  6. data/benchmarks/template_format.rb +1 -1
  7. data/docs/Templates.md +21 -21
  8. data/docs/WhatsNew.md +16 -2
  9. data/lib/yard.rb +23 -3
  10. data/lib/yard/autoload.rb +14 -13
  11. data/lib/yard/cli/command.rb +11 -3
  12. data/lib/yard/cli/command_parser.rb +4 -4
  13. data/lib/yard/cli/config.rb +2 -2
  14. data/lib/yard/cli/diff.rb +60 -16
  15. data/lib/yard/cli/graph.rb +5 -2
  16. data/lib/yard/cli/help.rb +1 -1
  17. data/lib/yard/cli/list.rb +2 -2
  18. data/lib/yard/cli/server.rb +80 -13
  19. data/lib/yard/cli/stats.rb +8 -8
  20. data/lib/yard/cli/yardoc.rb +32 -78
  21. data/lib/yard/cli/yardopts_command.rb +109 -0
  22. data/lib/yard/cli/yri.rb +2 -2
  23. data/lib/yard/code_objects/base.rb +3 -1
  24. data/lib/yard/code_objects/extra_file_object.rb +45 -6
  25. data/lib/yard/core_ext/file.rb +1 -1
  26. data/lib/yard/docstring.rb +10 -1
  27. data/lib/yard/i18n/locale.rb +11 -3
  28. data/lib/yard/i18n/message.rb +1 -1
  29. data/lib/yard/logging.rb +32 -7
  30. data/lib/yard/parser/ruby/ruby_parser.rb +8 -3
  31. data/lib/yard/parser/source_parser.rb +1 -2
  32. data/lib/yard/rake/yardoc_task.rb +1 -2
  33. data/lib/yard/registry.rb +20 -1
  34. data/lib/yard/registry_store.rb +15 -1
  35. data/lib/yard/rubygems/backports/gem.rb +6 -5
  36. data/lib/yard/rubygems/backports/source_index.rb +17 -0
  37. data/lib/yard/rubygems/doc_manager.rb +1 -1
  38. data/lib/yard/server/commands/static_file_command.rb +17 -10
  39. data/lib/yard/server/library_version.rb +2 -2
  40. data/lib/yard/server/rack_adapter.rb +3 -3
  41. data/lib/yard/server/templates/default/layout/html/setup.rb +1 -1
  42. data/lib/yard/tags/directives.rb +1 -1
  43. data/lib/yard/templates/helpers/html_helper.rb +6 -4
  44. data/lib/yard/templates/template.rb +13 -1
  45. data/lib/yard/version.rb +3 -0
  46. data/spec/cli/config_spec.rb +2 -2
  47. data/spec/cli/diff_spec.rb +110 -23
  48. data/spec/cli/graph_spec.rb +12 -5
  49. data/spec/cli/help_spec.rb +1 -1
  50. data/spec/cli/server_spec.rb +243 -153
  51. data/spec/cli/stats_spec.rb +1 -1
  52. data/spec/cli/yardoc_spec.rb +36 -0
  53. data/spec/code_objects/base_spec.rb +15 -0
  54. data/spec/code_objects/constants_spec.rb +1 -1
  55. data/spec/code_objects/extra_file_object_spec.rb +15 -3
  56. data/spec/docstring_parser_spec.rb +4 -0
  57. data/spec/docstring_spec.rb +18 -0
  58. data/spec/handlers/module_function_handler_spec.rb +23 -0
  59. data/spec/i18n/locale_spec.rb +7 -1
  60. data/spec/parser/ruby/ruby_parser_spec.rb +26 -0
  61. data/spec/parser/source_parser_spec.rb +18 -6
  62. data/spec/rake/yardoc_task_spec.rb +28 -19
  63. data/spec/registry_spec.rb +34 -0
  64. data/spec/registry_store_spec.rb +10 -0
  65. data/spec/rubygems/doc_manager_spec.rb +1 -1
  66. data/spec/server/commands/static_file_command_spec.rb +3 -3
  67. data/spec/spec_helper.rb +22 -3
  68. data/spec/templates/helpers/html_helper_spec.rb +10 -8
  69. data/templates/default/fulldoc/html/frames.erb +1 -1
  70. data/templates/default/fulldoc/html/setup.rb +1 -1
  71. data/yard.gemspec +24 -0
  72. metadata +7 -5
@@ -205,7 +205,7 @@ module YARD
205
205
  #
206
206
  # === Escaping Interpolation
207
207
  #
208
- # Interpolation can be escaped by prefixing the +$+ with +\+, like so:
208
+ # Interpolation can be escaped by prefixing the +$+ with +\\\+, like so:
209
209
  #
210
210
  # # @!macro foo
211
211
  # # I have \$2.00 USD.
@@ -60,7 +60,8 @@ module YARD
60
60
  if provider.to_s == 'RDiscount'
61
61
  provider.new(text, :autolink).to_html
62
62
  elsif provider.to_s == 'RedcarpetCompat'
63
- provider.new(text, :gh_blockcode, :fenced_code, :autolink).to_html
63
+ provider.new(text, :no_intraemphasis, :gh_blockcode,
64
+ :fenced_code, :autolink).to_html
64
65
  else
65
66
  provider.new(text).to_html
66
67
  end
@@ -508,11 +509,12 @@ module YARD
508
509
  # @return [String] the current character set
509
510
  # @since 0.5.4
510
511
  def charset
511
- if @file && RUBY19
512
+ has_encoding = defined?(::Encoding)
513
+ if @file && has_encoding
512
514
  lang = @file.contents.encoding.to_s
513
515
  else
514
- return 'utf-8' unless RUBY19 || lang = ENV['LANG']
515
- if RUBY19
516
+ return 'utf-8' unless has_encoding || lang = ENV['LANG']
517
+ if has_encoding
516
518
  lang = ::Encoding.default_external.name.downcase
517
519
  else
518
520
  lang = lang.downcase.split('.').last
@@ -58,13 +58,25 @@ module YARD
58
58
  module ClassMethods
59
59
  attr_accessor :path, :full_path
60
60
 
61
+ # @return [Array<String>] a list of full paths
62
+ # @note This method caches path results. Paths should not be modified
63
+ # after this method is called; call {#reset_full_paths} to reset cache.
61
64
  def full_paths
62
- included_modules.inject([full_path]) do |paths, mod|
65
+ reset_full_paths unless defined? @cached_included_modules
66
+ return @full_paths if included_modules == @cached_included_modules
67
+
68
+ @cached_included_modules = included_modules
69
+ @full_paths = included_modules.inject([full_path]) do |paths, mod|
63
70
  paths |= mod.full_paths if mod.respond_to?(:full_paths)
64
71
  paths
65
72
  end
66
73
  end
67
74
 
75
+ # Resets cache for {#full_paths}
76
+ def reset_full_paths
77
+ @cached_included_modules = nil
78
+ end
79
+
68
80
  def initialize(path, full_paths)
69
81
  full_path = full_paths.shift
70
82
  self.path = path
@@ -0,0 +1,3 @@
1
+ module YARD
2
+ VERSION = "0.8.3"
3
+ end
@@ -17,7 +17,7 @@ describe YARD::CLI::Config do
17
17
  it "should accept --list" do
18
18
  opts = YARD::Config.options
19
19
  YAML.should_receive(:dump).twice.and_return("--- foo\nbar\nbaz")
20
- @config.should_receive(:puts).twice.with("bar\nbaz")
20
+ log.should_receive(:puts).twice.with("bar\nbaz")
21
21
  run
22
22
  run('--list')
23
23
  YARD::Config.options.should == opts
@@ -27,7 +27,7 @@ describe YARD::CLI::Config do
27
27
  describe 'Viewing an item' do
28
28
  it "should view item if no value is given" do
29
29
  YARD::Config.options[:foo] = 'bar'
30
- @config.should_receive(:puts).with('"bar"')
30
+ log.should_receive(:puts).with('"bar"')
31
31
  run 'foo'
32
32
  YARD::Config.options[:foo].should == 'bar'
33
33
  end
@@ -12,7 +12,7 @@ describe YARD::CLI::Diff do
12
12
  describe 'Argument handling' do
13
13
  it "should exit if there is only one gem name" do
14
14
  @diff.should_receive(:exit)
15
- @diff.should_receive(:puts).with(/Usage/)
15
+ log.should_receive(:puts).with(/Usage/)
16
16
  @diff.run
17
17
  end
18
18
  end
@@ -29,13 +29,37 @@ describe YARD::CLI::Diff do
29
29
  @objects1 ||= %w( C#fooey C#baz D.bar )
30
30
  @objects2 ||= %w( A A::B A::B::C A.foo A#foo B C.foo C.bar C#baz )
31
31
  @objects = [@objects1, @objects2]
32
- @diff.should_receive(:load_gem_data).ordered.with('gem1').and_return(true)
33
- @diff.should_receive(:load_gem_data).ordered.with('gem2').and_return(true)
34
- Registry.should_receive(:all).twice.and_return do
35
- @objects[@all_call += 1].map {|o| P(o) }
32
+ @diff.should_receive(:load_gem_data).ordered.with('gem1') do
33
+ Registry.clear
34
+ YARD.parse_string <<-eof
35
+ class C
36
+ def fooey; end
37
+ def baz; FOO end
38
+ end
39
+ class D
40
+ def self.bar; end
41
+ end
42
+ eof
36
43
  end
37
- @diff.stub!(:print) {|data| @data << data }
38
- @diff.stub!(:puts) {|*args| @data << args.join("\n"); @data << "\n" }
44
+ @diff.should_receive(:load_gem_data).ordered.with('gem2') do
45
+ Registry.clear
46
+ YARD.parse_string <<-eof
47
+ module A
48
+ module B
49
+ class C; end
50
+ end
51
+ def self.foo; end
52
+ def foo; end
53
+ end
54
+ class C
55
+ def self.foo; end
56
+ def self.bar; end
57
+ def baz; BAR end
58
+ end
59
+ eof
60
+ end
61
+ log.stub!(:print) {|data| @data << data }
62
+ log.stub!(:puts) {|*args| @data << args.join("\n"); @data << "\n" }
39
63
  @diff.run(*(args + ['gem1', 'gem2']))
40
64
  end
41
65
 
@@ -44,16 +68,33 @@ describe YARD::CLI::Diff do
44
68
  @data.string.should == <<-eof
45
69
  Added objects:
46
70
 
47
- A (...)
48
- B
49
- C.bar
50
- C.foo
71
+ A ((stdin):1) (...)
72
+ A::B::C ((stdin):3)
73
+ C.bar ((stdin):10)
74
+ C.foo ((stdin):9)
75
+
76
+ Modified objects:
77
+
78
+ C#baz ((stdin):3)
51
79
 
52
80
  Removed objects:
53
81
 
54
- C#fooey
55
- D.bar
82
+ C#fooey ((stdin):2)
83
+ D ((stdin):5) (...)
56
84
 
85
+ eof
86
+ end
87
+
88
+ it "should accept --compact" do
89
+ run('--compact')
90
+ @data.string.should == <<-eof
91
+ A A ((stdin):1) (...)
92
+ A A::B::C ((stdin):3)
93
+ A C.bar ((stdin):10)
94
+ A C.foo ((stdin):9)
95
+ M C#baz ((stdin):3)
96
+ D C#fooey ((stdin):2)
97
+ D D ((stdin):5) (...)
57
98
  eof
58
99
  end
59
100
 
@@ -63,23 +104,69 @@ eof
63
104
  @data.string.should == <<-eof
64
105
  Added objects:
65
106
 
66
- A
67
- A#foo
68
- A.foo
69
- A::B
70
- A::B::C
71
- B
72
- C.bar
73
- C.foo
107
+ A ((stdin):1)
108
+ A#foo ((stdin):6)
109
+ A.foo ((stdin):5)
110
+ A::B ((stdin):2)
111
+ A::B::C ((stdin):3)
112
+ C.bar ((stdin):10)
113
+ C.foo ((stdin):9)
114
+
115
+ Modified objects:
116
+
117
+ C#baz ((stdin):3)
74
118
 
75
119
  Removed objects:
76
120
 
77
- C#fooey
78
- D.bar
121
+ C#fooey ((stdin):2)
122
+ D ((stdin):5)
123
+ D.bar ((stdin):6)
79
124
 
80
125
  eof
81
126
  end
82
127
  end
128
+
129
+ it "should accept --compact and --all" do
130
+ run('--compact', '--all')
131
+ @data.string.should == <<-eof
132
+ A A ((stdin):1)
133
+ A A#foo ((stdin):6)
134
+ A A.foo ((stdin):5)
135
+ A A::B ((stdin):2)
136
+ A A::B::C ((stdin):3)
137
+ A C.bar ((stdin):10)
138
+ A C.foo ((stdin):9)
139
+ M C#baz ((stdin):3)
140
+ D C#fooey ((stdin):2)
141
+ D D ((stdin):5)
142
+ D D.bar ((stdin):6)
143
+ eof
144
+ end
145
+
146
+ it "should accept --no-modified" do
147
+ run('--compact', '--no-modified')
148
+ @data.string.should == <<-eof
149
+ A A ((stdin):1) (...)
150
+ A A::B::C ((stdin):3)
151
+ A C.bar ((stdin):10)
152
+ A C.foo ((stdin):9)
153
+ D C#fooey ((stdin):2)
154
+ D D ((stdin):5) (...)
155
+ eof
156
+ end
157
+
158
+ it "should accept --query" do
159
+ run('--compact', '--query', 'o.type == :method')
160
+ @data.string.should == <<-eof
161
+ A A#foo ((stdin):6)
162
+ A A.foo ((stdin):5)
163
+ A C.bar ((stdin):10)
164
+ A C.foo ((stdin):9)
165
+ M C#baz ((stdin):3)
166
+ D C#fooey ((stdin):2)
167
+ D D.bar ((stdin):6)
168
+ eof
169
+ end
83
170
  end
84
171
 
85
172
  describe 'File searching' do
@@ -1,10 +1,17 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe YARD::CLI::Yardoc do
3
+ describe YARD::CLI::Graph do
4
4
  it "should serialize output" do
5
- Registry.should_receive(:load)
6
- @graph = YARD::CLI::Graph.new
7
- @graph.options.serializer.should_receive(:serialize).once
8
- @graph.run
5
+ Registry.should_receive(:load).at_least(1).times
6
+ subject.stub(:yardopts) { [] }
7
+ subject.options.serializer.should_receive(:serialize).once
8
+ subject.run
9
+ end
10
+
11
+ it 'should read yardoc file from .yardopts' do
12
+ subject.stub(:yardopts) { %w(--db /path/to/db) }
13
+ subject.options.serializer.should_receive(:serialize).once
14
+ subject.run
15
+ Registry.yardoc_file.should == '/path/to/db'
9
16
  end
10
17
  end
@@ -15,7 +15,7 @@ describe YARD::CLI::Help do
15
15
  it "should show all commands if command isn't found" do
16
16
  CLI::CommandParser.should_receive(:run).with('--help')
17
17
  help = CLI::Help.new
18
- help.should_receive(:puts).with(/not found/)
18
+ log.should_receive(:puts).with(/not found/)
19
19
  help.run('unknown')
20
20
  end
21
21
  end
@@ -4,14 +4,24 @@ class Server::WebrickAdapter; def start; end end
4
4
 
5
5
  describe YARD::CLI::Server do
6
6
  before do
7
+ CLI::Yardoc.stub!(:run)
7
8
  @no_verify_libraries = false
9
+ @set_libraries = true
8
10
  @no_adapter_mock = false
9
11
  @libraries = {}
10
12
  @options = {:single_library => true, :caching => false}
11
13
  @server_options = {:Port => 8808}
12
14
  @adapter = mock(:adapter)
13
15
  @adapter.stub!(:setup)
14
- @cli = YARD::CLI::Server.new
16
+ new_cli
17
+ end
18
+
19
+ after(:all) do
20
+ Server::Adapter.shutdown
21
+ end
22
+
23
+ def new_cli
24
+ @cli = subject
15
25
  end
16
26
 
17
27
  def rack_required
@@ -27,193 +37,273 @@ describe YARD::CLI::Server do
27
37
  end
28
38
 
29
39
  def run(*args)
30
- if @libraries.empty?
31
- library = Server::LibraryVersion.new(File.basename(Dir.pwd), nil, File.expand_path('.yardoc'))
40
+ if @set_libraries && @libraries.empty?
41
+ library = Server::LibraryVersion.new(
42
+ File.basename(Dir.pwd), nil, File.expand_path('.yardoc'))
32
43
  @libraries = {library.name => [library]}
33
44
  end
34
45
  unless @no_verify_libraries
35
- @libraries.values.each {|libs| libs.each {|lib| File.should_receive(:exist?).at_least(1).times.with(File.expand_path(lib.yardoc_file)).and_return(true) } }
46
+ @libraries.values.each do |libs|
47
+ libs.each do |lib|
48
+ yfile = File.expand_path(lib.yardoc_file)
49
+ File.stub!(:exist?).with(yfile).and_return(true)
50
+ end
51
+ end
36
52
  end
37
53
  unless @no_adapter_mock
38
54
  @cli.stub!(:adapter).and_return(@adapter)
39
- @adapter.should_receive(:new).with(@libraries, @options, @server_options).and_return(@adapter)
55
+ @adapter.should_receive(:new).
56
+ with(@libraries, @options, @server_options).and_return(@adapter)
40
57
  @adapter.should_receive(:start)
41
58
  end
59
+
42
60
  @cli.run(*args.flatten)
43
- @cli = YARD::CLI::Server.new
44
- end
61
+ assert_libraries @libraries, @cli.libraries
45
62
 
46
- it "should default to current dir if no library is specified" do
47
- Dir.should_receive(:pwd).and_return('/path/to/foo')
48
- @libraries['foo'] = [Server::LibraryVersion.new('foo', nil, File.expand_path('.yardoc'))]
49
- run
63
+ new_cli
50
64
  end
51
65
 
52
- it "should use .yardoc as yardoc file is library list is odd" do
53
- @libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('.yardoc'))]
54
- run 'a'
66
+ def assert_libraries(expected_libs, actual_libs)
67
+ actual_libs.should == expected_libs
68
+ expected_libs.each do |name, libs|
69
+ libs.each_with_index do |expected,i|
70
+ actual = actual_libs[name][i]
71
+ [:source, :source_path, :yardoc_file].each do |m|
72
+ actual.send(m).should == expected.send(m)
73
+ end
74
+ end
75
+ end
55
76
  end
56
77
 
57
- it "should force multi library if more than one library is listed" do
58
- @options[:single_library] = false
59
- @libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('b'))]
60
- @libraries['c'] = [Server::LibraryVersion.new('c', nil, File.expand_path('.yardoc'))]
61
- run %w(a b c)
78
+ # Mocks the existence of a file.
79
+ def mock_file(filename, content = nil)
80
+ File.stub!(:exist?).with(filename).and_return(true)
81
+ File.stub!(:read_binary).with(filename).and_return(content) if content
82
+ filename_e = File.expand_path(filename)
83
+ mock_file(filename_e) unless filename_e == filename
62
84
  end
63
85
 
64
- it "should accept -m, --multi-library" do
65
- @options[:single_library] = false
66
- run '-m'
67
- run '--multi-library'
68
- end
86
+ describe 'when .yardopts file exists' do
87
+ before :each do
88
+ Registry.yardoc_file = Registry::DEFAULT_YARDOC_FILE
89
+ Dir.stub!(:pwd).and_return('/path/to/bar')
90
+ @name = 'bar'
91
+ end
69
92
 
70
- it "should accept -c, --cache" do
71
- @options[:caching] = true
72
- run '-c'
73
- run '--cache'
74
- end
93
+ it "should use .yardoc as the yardoc db if .yardopts doesn't specify an alternate path" do
94
+ mock_file '/path/to/bar/.yardopts', '--protected'
95
+ @libraries[@name] = [Server::LibraryVersion.new(@name, nil, '/path/to/bar/.yardoc')]
96
+ @libraries.values[0][0].source_path = '/path/to/bar'
97
+ run
98
+ end
75
99
 
76
- it "should accept -r, --reload" do
77
- @options[:incremental] = true
78
- run '-r'
79
- run '--reload'
80
- end
100
+ it "should use the yardoc db location specified by .yardopts" do
101
+ mock_file '/path/to/bar/.yardopts', '--db foo'
102
+ @libraries[@name] = [Server::LibraryVersion.new(@name, nil, '/path/to/bar/foo')]
103
+ @libraries.values[0][0].source_path = '/path/to/bar'
104
+ run
105
+ end
81
106
 
82
- it "should accept -d, --daemon" do
83
- @server_options[:daemonize] = true
84
- run '-d'
85
- run '--daemon'
107
+ it "should parse .yardopts when the library list is odd" do
108
+ mock_file '/path/to/bar/.yardopts', '--db foo'
109
+ @libraries['a'] = [Server::LibraryVersion.new('a', nil, '/path/to/bar/foo')]
110
+ @libraries.values[0][0].source_path = '/path/to/bar'
111
+ run 'a'
112
+ end
86
113
  end
87
114
 
88
- it "should accept -p, --port" do
89
- @server_options[:Port] = 10
90
- run '-p', '10'
91
- run '--port', '10'
92
- end
115
+ describe "when .yardopts file doesn't exist" do
116
+ before :each do
117
+ File.stub(:exist?).with(/^(.*[\\\/])?\.yardopts$/).and_return(false)
118
+ end
93
119
 
94
- it "should accept --docroot" do
95
- @server_options[:DocumentRoot] = Dir.pwd + '/__foo/bar'
96
- run '--docroot', '__foo/bar'
97
- end
120
+ it "should default to .yardoc if no library is specified" do
121
+ Dir.should_receive(:pwd).at_least(:once).and_return('/path/to/foo')
122
+ @libraries['foo'] = [Server::LibraryVersion.new('foo', nil, '/path/to/foo/.yardoc')]
123
+ run
124
+ end
98
125
 
99
- it "should accept -a webrick to create WEBrick adapter" do
100
- @cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
101
- run '-a', 'webrick'
102
- end
126
+ it "should use .yardoc as yardoc file if library list is odd" do
127
+ @libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('.yardoc'))]
128
+ run 'a'
129
+ end
103
130
 
104
- it "should accept -a rack to create Rack adapter" do
105
- rack_required
106
- @cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
107
- run '-a', 'rack'
108
- end
131
+ it "should force multi library if more than one library is listed" do
132
+ File.stub(:exist?).with('b').and_return(true)
133
+ @options[:single_library] = false
134
+ @libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('b'))]
135
+ @libraries['c'] = [Server::LibraryVersion.new('c', nil, File.expand_path('.yardoc'))]
136
+ run %w(a b c)
137
+ end
109
138
 
110
- it "should default to Rack adapter if exists on system" do
111
- rack_required
112
- @cli.should_receive(:require).with('rubygems').and_return(false)
113
- @cli.should_receive(:require).with('rack').and_return(true)
114
- @cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
115
- @cli.send(:select_adapter)
139
+ it "should fail if specified directory does not exist" do
140
+ @set_libraries = false
141
+ File.stub(:exist?).with('b').and_return(false)
142
+ log.should_receive(:warn).with(/Cannot find yardoc db for a: "b"/)
143
+ run %w(a b)
144
+ end
116
145
  end
117
146
 
118
- it "should fall back to WEBrick adapter if Rack is not on system" do
119
- @cli.should_receive(:require).with('rubygems').and_return(false)
120
- @cli.should_receive(:require).with('rack').and_raise(LoadError)
121
- @cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
122
- @cli.send(:select_adapter)
123
- end
147
+ describe 'General options' do
148
+ before do
149
+ File.stub(:exist?).with(/\.yardopts$/).and_return(false)
150
+ end
124
151
 
125
- it "should accept -s, --server" do
126
- @server_options[:server] = 'thin'
127
- run '-s', 'thin'
128
- run '--server', 'thin'
129
- end
152
+ it "should accept -m, --multi-library" do
153
+ @options[:single_library] = false
154
+ run '-m'
155
+ run '--multi-library'
156
+ end
130
157
 
131
- it "should accept -g, --gems" do
132
- @no_verify_libraries = true
133
- @options[:single_library] = false
134
- @libraries['gem1'] = [Server::LibraryVersion.new('gem1', '1.0.0', nil, :gem)]
135
- @libraries['gem2'] = [Server::LibraryVersion.new('gem2', '1.0.0', nil, :gem)]
136
- gem1 = mock(:gem1)
137
- gem1.stub!(:name).and_return('gem1')
138
- gem1.stub!(:version).and_return('1.0.0')
139
- gem1.stub!(:full_gem_path).and_return('/path/to/foo')
140
- gem2 = mock(:gem2)
141
- gem2.stub!(:name).and_return('gem2')
142
- gem2.stub!(:version).and_return('1.0.0')
143
- gem2.stub!(:full_gem_path).and_return('/path/to/bar')
144
- specs = {'gem1' => gem1, 'gem2' => gem2}
145
- source = mock(:source_index)
146
- source.stub!(:find_name).and_return do |k, ver|
147
- k == '' ? specs.values : specs.grep(k).map {|name| specs[name] }
148
- end
149
- Gem.stub!(:source_index).and_return(source)
150
- run '-g'
151
- run '--gems'
152
- end
158
+ it "should accept -c, --cache" do
159
+ @options[:caching] = true
160
+ run '-c'
161
+ run '--cache'
162
+ end
153
163
 
154
- it "should accept -G, --gemfile" do
155
- bundler_required
156
- @no_verify_libraries = true
157
- @options[:single_library] = false
158
-
159
- @libraries['gem1'] = [Server::LibraryVersion.new('gem1', '1.0.0', nil, :gem)]
160
- @libraries['gem2'] = [Server::LibraryVersion.new('gem2', '1.0.0', nil, :gem)]
161
- gem1 = mock(:gem1)
162
- gem1.stub!(:name).and_return('gem1')
163
- gem1.stub!(:version).and_return('1.0.0')
164
- gem1.stub!(:full_gem_path).and_return('/path/to/foo')
165
- gem2 = mock(:gem2)
166
- gem2.stub!(:name).and_return('gem2')
167
- gem2.stub!(:version).and_return('1.0.0')
168
- gem2.stub!(:full_gem_path).and_return('/path/to/bar')
169
- specs = {'gem1' => gem1, 'gem2' => gem2}
170
- lockfile_parser = mock(:new)
171
- lockfile_parser.stub!(:specs).and_return([gem1, gem2])
172
- Bundler::LockfileParser.stub!(:new).and_return(lockfile_parser)
173
-
174
- File.should_receive(:exists?).at_least(2).times.with("Gemfile.lock").and_return(true)
175
- File.stub!(:read)
176
-
177
- run '-G'
178
- run '--gemfile'
179
-
180
- File.should_receive(:exists?).with("different_name.lock").and_return(true)
181
- run '--gemfile', 'different_name'
182
- end
164
+ it "should accept -r, --reload" do
165
+ @options[:incremental] = true
166
+ run '-r'
167
+ run '--reload'
168
+ end
183
169
 
184
- it "should warn if lockfile is not found (with -G)" do
185
- bundler_required
186
- File.should_receive(:exists?).with('somefile.lock').and_return(false)
187
- log.should_receive(:warn).with(/Cannot find somefile.lock/)
188
- run '-G', 'somefile'
189
- end
170
+ it "should accept -d, --daemon" do
171
+ @server_options[:daemonize] = true
172
+ run '-d'
173
+ run '--daemon'
174
+ end
190
175
 
191
- it "should error if Bundler not available (with -G)" do
192
- @cli.should_receive(:require).with('bundler').and_raise(LoadError)
193
- log.should_receive(:error).with(/Bundler not available/)
194
- run '-G'
195
- end
176
+ it "should accept -p, --port" do
177
+ @server_options[:Port] = 10
178
+ run '-p', '10'
179
+ run '--port', '10'
180
+ end
196
181
 
197
- it "should load template paths after adapter template paths" do
198
- unstub_adapter
199
- @cli.adapter = Server::WebrickAdapter
200
- run '-t', 'foo'
201
- Templates::Engine.template_paths.last.should == 'foo'
202
- end
182
+ it "should accept --docroot" do
183
+ @server_options[:DocumentRoot] = Dir.pwd + '/__foo/bar'
184
+ run '--docroot', '__foo/bar'
185
+ end
186
+
187
+ it "should accept -a webrick to create WEBrick adapter" do
188
+ @cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
189
+ run '-a', 'webrick'
190
+ end
191
+
192
+ it "should accept -a rack to create Rack adapter" do
193
+ rack_required
194
+ @cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
195
+ run '-a', 'rack'
196
+ end
197
+
198
+ it "should default to Rack adapter if exists on system" do
199
+ rack_required
200
+ @cli.should_receive(:require).with('rubygems').and_return(false)
201
+ @cli.should_receive(:require).with('rack').and_return(true)
202
+ @cli.should_receive(:adapter=).with(YARD::Server::RackAdapter)
203
+ @cli.send(:select_adapter)
204
+ end
205
+
206
+ it "should fall back to WEBrick adapter if Rack is not on system" do
207
+ @cli.should_receive(:require).with('rubygems').and_return(false)
208
+ @cli.should_receive(:require).with('rack').and_raise(LoadError)
209
+ @cli.should_receive(:adapter=).with(YARD::Server::WebrickAdapter)
210
+ @cli.send(:select_adapter)
211
+ end
212
+
213
+ it "should accept -s, --server" do
214
+ @server_options[:server] = 'thin'
215
+ run '-s', 'thin'
216
+ run '--server', 'thin'
217
+ end
218
+
219
+ it "should accept -g, --gems" do
220
+ @no_verify_libraries = true
221
+ @options[:single_library] = false
222
+ @libraries['gem1'] = [Server::LibraryVersion.new('gem1', '1.0.0', nil, :gem)]
223
+ @libraries['gem2'] = [Server::LibraryVersion.new('gem2', '1.0.0', nil, :gem)]
224
+ gem1 = mock(:gem1)
225
+ gem1.stub!(:name).and_return('gem1')
226
+ gem1.stub!(:version).and_return('1.0.0')
227
+ gem1.stub!(:full_gem_path).and_return('/path/to/foo')
228
+ gem2 = mock(:gem2)
229
+ gem2.stub!(:name).and_return('gem2')
230
+ gem2.stub!(:version).and_return('1.0.0')
231
+ gem2.stub!(:full_gem_path).and_return('/path/to/bar')
232
+ specs = {'gem1' => gem1, 'gem2' => gem2}
233
+ source = mock(:source_index)
234
+ source.stub!(:find_name).and_return do |k, ver|
235
+ k == '' ? specs.values : specs.grep(k).map {|name| specs[name] }
236
+ end
237
+ Gem.stub!(:source_index).and_return(source)
238
+ run '-g'
239
+ run '--gems'
240
+ end
241
+
242
+ it "should accept -G, --gemfile" do
243
+ bundler_required
244
+ @no_verify_libraries = true
245
+ @options[:single_library] = false
246
+
247
+ @libraries['gem1'] = [Server::LibraryVersion.new('gem1', '1.0.0', nil, :gem)]
248
+ @libraries['gem2'] = [Server::LibraryVersion.new('gem2', '1.0.0', nil, :gem)]
249
+ gem1 = mock(:gem1)
250
+ gem1.stub!(:name).and_return('gem1')
251
+ gem1.stub!(:version).and_return('1.0.0')
252
+ gem1.stub!(:full_gem_path).and_return('/path/to/foo')
253
+ gem2 = mock(:gem2)
254
+ gem2.stub!(:name).and_return('gem2')
255
+ gem2.stub!(:version).and_return('1.0.0')
256
+ gem2.stub!(:full_gem_path).and_return('/path/to/bar')
257
+ specs = {'gem1' => gem1, 'gem2' => gem2}
258
+ lockfile_parser = mock(:new)
259
+ lockfile_parser.stub!(:specs).and_return([gem1, gem2])
260
+ Bundler::LockfileParser.stub!(:new).and_return(lockfile_parser)
261
+
262
+ File.should_receive(:exist?).at_least(2).times.with("Gemfile.lock").and_return(true)
263
+ File.stub!(:read)
264
+
265
+ run '-G'
266
+ run '--gemfile'
267
+
268
+ File.should_receive(:exist?).with("different_name.lock").and_return(true)
269
+ run '--gemfile', 'different_name'
270
+ end
271
+
272
+ it "should warn if lockfile is not found (with -G)" do
273
+ bundler_required
274
+ File.should_receive(:exist?).with(/\.yardopts$/).at_least(:once).and_return(false)
275
+ File.should_receive(:exist?).with('somefile.lock').and_return(false)
276
+ log.should_receive(:warn).with(/Cannot find somefile.lock/)
277
+ run '-G', 'somefile'
278
+ end
279
+
280
+ it "should error if Bundler not available (with -G)" do
281
+ @cli.should_receive(:require).with('bundler').and_raise(LoadError)
282
+ log.should_receive(:error).with(/Bundler not available/)
283
+ run '-G'
284
+ end
285
+
286
+ it "should load template paths after adapter template paths" do
287
+ unstub_adapter
288
+ @cli.adapter = Server::WebrickAdapter
289
+ run '-t', 'foo'
290
+ Templates::Engine.template_paths.last.should == 'foo'
291
+ end
203
292
 
204
- it "should load ruby code (-e) after adapter" do
205
- unstub_adapter
206
- @cli.adapter = Server::WebrickAdapter
207
- path = File.dirname(__FILE__) + '/tmp.adapterscript.rb'
208
- begin
209
- File.open(path, 'w') do |f|
210
- f.puts "YARD::Templates::Engine.register_template_path 'foo'"
211
- f.flush
212
- run '-e', f.path
213
- Templates::Engine.template_paths.last.should == 'foo'
293
+ it "should load ruby code (-e) after adapter" do
294
+ unstub_adapter
295
+ @cli.adapter = Server::WebrickAdapter
296
+ path = File.dirname(__FILE__) + '/tmp.adapterscript.rb'
297
+ begin
298
+ File.open(path, 'w') do |f|
299
+ f.puts "YARD::Templates::Engine.register_template_path 'foo'"
300
+ f.flush
301
+ run '-e', f.path
302
+ Templates::Engine.template_paths.last.should == 'foo'
303
+ end
304
+ ensure
305
+ File.unlink(path)
214
306
  end
215
- ensure
216
- File.unlink(path)
217
307
  end
218
308
  end
219
309
  end