File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ def show_diff(destination, content) #:nodoc:
314314 diff_cmd = ENV [ "THOR_DIFF" ] || ENV [ "RAILS_DIFF" ] || "diff -u"
315315
316316 require "tempfile"
317- Tempfile . open ( File . basename ( destination ) , File . dirname ( destination ) ) do |temp |
317+ Tempfile . open ( File . basename ( destination ) , File . dirname ( destination ) , binmode : true ) do |temp |
318318 temp . write content
319319 temp . rewind
320320 system %(#{ diff_cmd } "#{ destination } " "#{ temp . path } ")
Original file line number Diff line number Diff line change @@ -81,6 +81,29 @@ def file
8181 expect ( File . stat ( original ) . mode ) . to eq ( File . stat ( copy ) . mode )
8282 end
8383
84+ it "shows the diff when there is a collision and source has utf-8 characters" do
85+ previous_internal = Encoding . default_internal
86+
87+ silence_warnings do
88+ Encoding . default_internal = Encoding ::UTF_8
89+ end
90+
91+ destination = File . join ( destination_root , "encoding_with_utf8.thor" )
92+ FileUtils . mkdir_p ( destination_root )
93+
94+ File . write ( destination , "blabla" )
95+
96+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . and_return ( "d" , "y" )
97+ expect ( runner . shell ) . to receive ( :system ) . with ( /diff -u/ )
98+ action :copy_file , "encoding_with_utf8.thor"
99+
100+ exists_and_identical? ( "encoding_with_utf8.thor" , "encoding_with_utf8.thor" )
101+ ensure
102+ silence_warnings do
103+ Encoding . default_internal = previous_internal
104+ end
105+ end
106+
84107 it "logs status" do
85108 expect ( action ( :copy_file , "command.thor" ) ) . to eq ( " create command.thor\n " )
86109 end
You can’t perform that action at this time.
0 commit comments