Skip to content
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.
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 @@ -314,7 +314,7 @@ def show_diff(destination, content) #:nodoc:
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"

require "tempfile"
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
Tempfile.open(File.basename(destination), File.dirname(destination), binmode: true) do |temp|
temp.write content
temp.rewind
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
Expand Down
23 changes: 23 additions & 0 deletions spec/actions/file_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ def file
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
end

it "shows the diff 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")

expect(Thor::LineEditor).to receive(:readline).and_return("d", "y")
expect(runner.shell).to receive(:system).with(/diff -u/)
action :copy_file, "encoding_with_utf8.thor"

exists_and_identical?("encoding_with_utf8.thor", "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