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

fix: display a warning when file exists #81

Merged
merged 1 commit into from Oct 31, 2018
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
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
return Jekyll.logger.warn "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 and abort" do
output = capture_stdout { described_class.process(args) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does abort_with not kill the test process?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it does, the tests are passing but are wrong. If I change the string in the test, it still passes. How should I test that we abort?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply warn and return instead of a hard abort..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a simple return file gets overwritten. I thought this was workin' after testing it locally but this isn't, shouldn't have merged 😕

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