Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created August 25, 2011 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsutphin/1172120 to your computer and use it in GitHub Desktop.
Save rsutphin/1172120 to your computer and use it in GitHub Desktop.
Demonstrating two encoding-related issues for fakefs
# 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'
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
@rsutphin
Copy link
Author

N.b.: gist doesn't seem to display UTF-8 properly. If you clone the gist, the problem will be clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment