Created
August 25, 2011 22:07
-
-
Save rsutphin/1172120 to your computer and use it in GitHub Desktop.
Demonstrating two encoding-related issues for fakefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
def test(env) | |
fn = 'foo' | |
File.open(fn, 'w:UTF-8') { |f| f.write '☃' } | |
begin | |
puts "Read from #{env} file: #{File.read(fn, :encoding => 'UTF-8')}" | |
rescue => e | |
puts "ERROR: File.read failed for #{env}: #{e}" | |
end | |
begin | |
File.open(fn, 'r', :encoding => 'UTF-8') do |f| | |
puts "IO encoding on #{env} filehandle: #{f.external_encoding}" | |
end | |
rescue => e | |
puts "ERROR: File.open failed for #{env}: #{e}" | |
end | |
end | |
puts RUBY_DESCRIPTION | |
puts | |
test 'real' | |
puts | |
require 'fakefs' | |
test 'fakefs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] | |
Read from real file: ☃ | |
IO encoding on real filehandle: UTF-8 | |
ERROR: File.read failed for fakefs: wrong number of arguments (2 for 1) | |
IO encoding on fakefs filehandle: US-ASCII |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
N.b.: gist doesn't seem to display UTF-8 properly. If you clone the gist, the problem will be clearer.