From 0108b22f3c99fa1d9bfb0ba4e72e2ded3fe4e281 Mon Sep 17 00:00:00 2001 From: Florian Thomas Date: Wed, 19 Apr 2017 19:50:25 +0100 Subject: [PATCH] create configuration from options only once in the boot process (#5487) Merge pull request 5487 --- lib/jekyll/command.rb | 1 + lib/jekyll/commands/serve.rb | 11 ++++++----- test/test_commands_serve.rb | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index 2a4fc77f..9150d24d 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -37,6 +37,7 @@ module Jekyll # # Returns a full Jekyll configuration def configuration_from_options(options) + return options if options.is_a?(Jekyll::Configuration) Jekyll.configuration(options) end diff --git a/lib/jekyll/commands/serve.rb b/lib/jekyll/commands/serve.rb index 16913595..622eda49 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -32,11 +32,12 @@ module Jekyll cmd.action do |_, opts| opts["serving"] = true opts["watch" ] = true unless opts.key?("watch") - config = opts["config"] - opts["url"] = default_url(opts) if Jekyll.env == "development" - Build.process(opts) - opts["config"] = config - Serve.process(opts) + + config = configuration_from_options(opts) + if Jekyll.env == "development" + config["url"] = default_url(config) + end + [Build, Serve].each { |klass| klass.process(config) } end end end diff --git a/test/test_commands_serve.rb b/test/test_commands_serve.rb index fa0f7f67..ef98bab4 100644 --- a/test/test_commands_serve.rb +++ b/test/test_commands_serve.rb @@ -82,16 +82,26 @@ class TestCommandsServe < JekyllUnitTest end should "keep config between build and serve" do - custom_options = { + options = { "config" => %w(_config.yml _development.yml), "serving" => true, "watch" => false, # for not having guard output when running the tests "url" => "http://localhost:4000", } + config = Jekyll::Configuration.from(options) - expect(Jekyll::Commands::Serve).to receive(:process).with(custom_options) - @merc.execute(:serve, { "config" => %w(_config.yml _development.yml), - "watch" => false, }) + allow(Jekyll::Command).to( + receive(:configuration_from_options).with(options).and_return(config) + ) + allow(Jekyll::Command).to( + receive(:configuration_from_options).with(config).and_return(config) + ) + + expect(Jekyll::Commands::Build).to( + receive(:process).with(config).and_call_original + ) + expect(Jekyll::Commands::Serve).to receive(:process).with(config) + @merc.execute(:serve, options) end context "in development environment" do @@ -175,5 +185,12 @@ class TestCommandsServe < JekyllUnitTest end end end + + should "read `configuration` only once" do + allow(Jekyll::Commands::Serve).to receive(:start_up_webrick) + + expect(Jekyll).to receive(:configuration).once.and_call_original + @merc.execute(:serve, { "watch" => false }) + end end end