Skip to content

Commit

Permalink
Merge pull request #998 from nanoc/gh-989-index-filenames-in-view
Browse files Browse the repository at this point in the history
Use config index_filenames in view command
  • Loading branch information
denisdefreyne committed Nov 21, 2016
2 parents 219fd85 + 38ab2e6 commit da1a76a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/nanoc/cli/commands/view.rb
Expand Up @@ -46,7 +46,7 @@ def run
use Rack::Head
use Adsf::Rack::IndexFileFinder,
root: site.config[:output_dir],
index_filenames: %w(index.html index.xhtml)
index_filenames: site.config[:index_filenames]
run Rack::File.new(site.config[:output_dir])
end.to_app

Expand Down
31 changes: 23 additions & 8 deletions spec/nanoc/cli/commands/view_spec.rb
Expand Up @@ -19,17 +19,32 @@ def run_nanoc_cmd(cmd)
Process.kill('TERM', pid)
end

it 'serves /index.html as /' do
File.write('output/index.html', 'Hello there! Nanoc loves you! <3')
run_nanoc_cmd(['view', '--port', '50385']) do
expect(Net::HTTP.get('0.0.0.0', '/', 50_385)).to eql('Hello there! Nanoc loves you! <3')
context 'default configuration' do
it 'serves /index.html as /' do
File.write('output/index.html', 'Hello there! Nanoc loves you! <3')
run_nanoc_cmd(['view', '--port', '50385']) do
expect(Net::HTTP.get('0.0.0.0', '/', 50_385)).to eql('Hello there! Nanoc loves you! <3')
end
end

it 'does not serve /index.xhtml as /' do
File.write('output/index.xhtml', 'Hello there! Nanoc loves you! <3')
run_nanoc_cmd(['view', '--port', '50385']) do
expect(Net::HTTP.get('0.0.0.0', '/', 50_385)).to eql("File not found: /\n")
end
end
end

it 'serves /index.xhtml as /' do
File.write('output/index.xhtml', 'Hello there! Nanoc loves you! <3')
run_nanoc_cmd(['view', '--port', '50385']) do
expect(Net::HTTP.get('0.0.0.0', '/', 50_385)).to eql('Hello there! Nanoc loves you! <3')
context 'index_filenames including index.xhtml' do
before do
File.write('nanoc.yaml', 'index_filenames: [index.xhtml]')
end

it 'serves /index.xhtml as /' do
File.write('output/index.xhtml', 'Hello there! Nanoc loves you! <3')
run_nanoc_cmd(['view', '--port', '50385']) do
expect(Net::HTTP.get('0.0.0.0', '/', 50_385)).to eql('Hello there! Nanoc loves you! <3')
end
end
end

Expand Down

0 comments on commit da1a76a

Please sign in to comment.