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