Skip to content

Commit

Permalink
Fix friends edit for multi-word EDITORs
Browse files Browse the repository at this point in the history
Fixes #251
  • Loading branch information
JacobEvelyn committed Apr 2, 2020
1 parent bf0a15c commit 6c4a0f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/friends/commands/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
puts "Opening \"#{filename}\" with \"#{editor}\"" unless global_options[:quiet]

# Mark the file for cleaning once the editor was closed correctly.
if Kernel.system(editor, filename)
if Kernel.system("#{editor} #{filename}")
@introvert = Friends::Introvert.new(filename: filename)
@clean_command = true
@dirty = true
Expand Down
31 changes: 31 additions & 0 deletions test/commands/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@
end
end

describe "when editor is multiple words" do
let(:editor) { "'cat -u'" }

describe "when output is quieted" do
let(:quiet) { "--quiet" }

it 'opens the file in the "editor"' do
stdout_only content
end

it "cleans the file" do
file_equals CONTENT # File is cleaned (no longer scrambled).
end
end

describe "when output is not quieted" do
let(:quiet) { nil }

# Since our "editor" is just `cat -u`, our STDOUT output will include both the opening
# message and the contents of the file.
it 'prints a message and opens the file in the "editor"' do
stdout_only "Opening \"#{filename}\" with \"#{editor.tr("'", '')}\""\
"\n#{content}File cleaned: \"#{filename}\""
end

it "cleans the file" do
file_equals CONTENT # File is cleaned (no longer scrambled).
end
end
end

describe "when editor does not exit successfully" do
let(:editor) { "'exit 1 #'" }

Expand Down

0 comments on commit 6c4a0f3

Please sign in to comment.