Skip to content

Commit

Permalink
Ensure that yard server -d (daemon mode) chdir's into the
Browse files Browse the repository at this point in the history
correct working directory when using rack.

Merge remote branch 'robgleeson/patch-server_daemon'

Closes #328
  • Loading branch information
lsegal committed May 23, 2011
2 parents 48d5ce2 + fb73589 commit 780545f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/yard/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def select_adapter
def add_libraries(args)
(0...args.size).step(2) do |index|
library, yardoc = args[index], args[index + 1]
yardoc ||= '.yardoc'
yardoc = yardoc.nil? ? File.expand_path('.yardoc') : File.expand_path(yardoc)
if File.exist?(yardoc)
libraries[library] ||= []
libraries[library] << YARD::Server::LibraryVersion.new(library, nil, yardoc)
Expand Down Expand Up @@ -142,18 +142,18 @@ def optparse(*args)
parse_options(opts, args)

if args.empty? && libraries.empty?
if !File.exist?('.yardoc')
if !File.exist? File.expand_path('.yardoc')
log.enter_level(Logger::INFO) do
log.info "No .yardoc file found in current directory, parsing source before starting server..."
end
Yardoc.run('-n')
end
add_libraries([File.basename(Dir.pwd), '.yardoc'])
add_libraries([File.basename(Dir.pwd), File.expand_path('.yardoc')])
else
add_libraries(args)
options[:single_library] = false if libraries.size > 1
end
end
end
end
end
end
14 changes: 7 additions & 7 deletions spec/cli/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def unstub_adapter

def run(*args)
if @libraries.empty?
library = Server::LibraryVersion.new(File.basename(Dir.pwd), nil, '.yardoc')
library = Server::LibraryVersion.new(File.basename(Dir.pwd), nil, File.expand_path('.yardoc'))
@libraries = {library.name => [library]}
end
unless @no_verify_libraries
@libraries.values.each {|libs| libs.each {|lib| File.should_receive(:exist?).at_least(1).times.with(lib.yardoc_file).and_return(true) } }
@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) } }
end
unless @no_adapter_mock
@cli.stub!(:adapter).and_return(@adapter)
Expand All @@ -40,19 +40,19 @@ def run(*args)

it "should default to current dir if no library is specified" do
Dir.should_receive(:pwd).and_return('/path/to/foo')
@libraries['foo'] = [Server::LibraryVersion.new('foo', nil, '.yardoc')]
@libraries['foo'] = [Server::LibraryVersion.new('foo', nil, File.expand_path('.yardoc'))]
run
end

it "should use .yardoc as yardoc file is library list is odd" do
@libraries['a'] = [Server::LibraryVersion.new('a', nil,'.yardoc')]
@libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('.yardoc'))]
run 'a'
end

it "should force multi library if more than one library is listed" do
@options[:single_library] = false
@libraries['a'] = [Server::LibraryVersion.new('a', nil, 'b')]
@libraries['c'] = [Server::LibraryVersion.new('c', nil, '.yardoc')]
@libraries['a'] = [Server::LibraryVersion.new('a', nil, File.expand_path('b'))]
@libraries['c'] = [Server::LibraryVersion.new('c', nil, File.expand_path('.yardoc'))]
run %w(a b c)
end

Expand Down Expand Up @@ -167,4 +167,4 @@ def run(*args)
end
end
end
end
end

0 comments on commit 780545f

Please sign in to comment.