Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create output dir when viewing #1261

Merged
merged 2 commits into from Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/nanoc/cli/commands/view.rb
Expand Up @@ -23,6 +23,9 @@ def run

config = Nanoc::Int::ConfigLoader.new.new_from_cwd

# Create output dir so that viewer/watcher doesn’t explode.
FileUtils.mkdir_p(config[:output_dir])

server =
Adsf::Server.new(
root: File.absolute_path(config[:output_dir]),
Expand Down
11 changes: 9 additions & 2 deletions spec/nanoc/cli/commands/view_spec.rb
Expand Up @@ -12,8 +12,8 @@ def run_nanoc_cmd(cmd)
begin
Net::HTTP.get('127.0.0.1', '/', 50_385)
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
sleep(0.1 * 1.2**i)
retry
sleep(0.1 * 1.1**i)
next
end
break
end
Expand Down Expand Up @@ -59,6 +59,13 @@ def run_nanoc_cmd(cmd)
end
end

it 'does not crash when output dir does not exist and --live-reload is given' do
FileUtils.rm_rf('output')
run_nanoc_cmd(['view', '--port', '50385', '--live-reload']) do
expect(Net::HTTP.get('127.0.0.1', '/', 50_385)).to eql("File not found: /\n")
end
end

it 'does not listen on non-local interfaces' do
addresses = Socket.getifaddrs.map(&:addr).select(&:ipv4?).map(&:ip_address)
non_local_addresses = addresses - ['127.0.0.1']
Expand Down