Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/thor/shell/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def answer_match(possibilities, answer, case_insensitive)

def merge(destination, content) #:nodoc:
require "tempfile"
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination), binmode: true) do |temp|
temp.write content
temp.rewind
system(*merge_tool, temp.path, destination)
Expand Down
22 changes: 22 additions & 0 deletions spec/actions/file_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ def file
end
end

it "launches the merge tool when there is a collision and source has utf-8 characters" do
previous_internal = Encoding.default_internal

silence_warnings do
Encoding.default_internal = Encoding::UTF_8
end

destination = File.join(destination_root, "encoding_with_utf8.thor")
FileUtils.mkdir_p(destination_root)

File.write(destination, "blabla")

allow(runner.shell).to receive(:merge_tool).and_return("meld")
expect(Thor::LineEditor).to receive(:readline).and_return("m")
expect(runner.shell).to receive(:system).with("meld", /encoding_with_utf8.thor/, /encoding_with_utf8.thor/)
action :copy_file, "encoding_with_utf8.thor"
ensure
silence_warnings do
Encoding.default_internal = previous_internal
end
end

it "logs status" do
expect(action(:copy_file, "command.thor")).to eq(" create command.thor\n")
end
Expand Down
Loading