Skip to content

Commit

Permalink
fix: display a warning when file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtyF committed Oct 31, 2018
1 parent f063a95 commit d7d808d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll-compose/file_creator.rb
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/draft_spec.rb
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/page_spec.rb
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/post_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit d7d808d

Please sign in to comment.