diff --git a/lib/jekyll-compose/file_creator.rb b/lib/jekyll-compose/file_creator.rb index 2a33789..2dfee9e 100644 --- a/lib/jekyll-compose/file_creator.rb +++ b/lib/jekyll-compose/file_creator.rb @@ -25,7 +25,7 @@ def file_path private def validate_should_write! - raise ArgumentError, "A #{file.resource_type} already exists at #{file_path}" if File.exist?(file_path) && !force + Jekyll.logger.abort_with "A #{file.resource_type} already exists at #{file_path}".yellow if File.exist?(file_path) && !force end def ensure_directory_exists diff --git a/spec/draft_spec.rb b/spec/draft_spec.rb index 908c785..ac2129c 100644 --- a/spec/draft_spec.rb +++ b/spec/draft_spec.rb @@ -63,10 +63,9 @@ FileUtils.touch path end - it "raises an error" do - expect(lambda { - capture_stdout { described_class.process(args) } - }).to raise_error("A draft already exists at _drafts/an-existing-draft.md") + it "displays a warning" do + output = capture_stdout { described_class.process(args) } + expect(output).to include("A draft already exists at _drafts/an-existing-draft.md".yellow) end it "overwrites if --force is given" do diff --git a/spec/page_spec.rb b/spec/page_spec.rb index fabb4bd..a631886 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -52,10 +52,9 @@ FileUtils.touch path end - it "raises an error" do - expect(lambda { - capture_stdout { described_class.process(args) } - }).to raise_error("A page already exists at #{filename}") + it "displays a warning" do + output = capture_stdout { described_class.process(args) } + expect(output).to include("A page already exists at #{filename}".yellow) end it "overwrites if --force is given" do diff --git a/spec/post_spec.rb b/spec/post_spec.rb index 7f5d4fa..f947af0 100644 --- a/spec/post_spec.rb +++ b/spec/post_spec.rb @@ -74,10 +74,9 @@ FileUtils.touch path end - it "raises an error" do - expect(lambda { - capture_stdout { described_class.process(args) } - }).to raise_error("A post already exists at _posts/#{filename}") + it "displays a warning" do + output = capture_stdout { described_class.process(args) } + expect(output).to include("A post already exists at _posts/#{filename}".yellow) end it "overwrites if --force is given" do