Ruby Iconv works with irb and ruby debugger but not in a unit test

Posted by Mark B on Stack Overflow See other posts from Stack Overflow or by Mark B
Published on 2010-06-15T15:10:02Z Indexed on 2010/06/15 15:12 UTC
Read the original article Hit count: 512

Filed under:
|
|
|

I'm running Ruby 1.8.7 with Rails 2.3.5 on Ubuntu 10.04 64-bit. I've written a method that should take a string like this, "École À la Découverte" and output a file-system name like this "ecole_a_la_decouverte":

(Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv "École À la Découverte").gsub(/[^\w\s-\—]/,'').gsub(/[^\w]|[_]/,' ').split.join('_').downcase

When I test this line in my code, the test always fails saying that "cole_la_dcouverte" is unequal to "ecole_a_la_decouverte". The odd thing is that if I insert a debugger line and use the debugger console the test passes. As well, running this line manually in irb seems to work.

Does anyone know what's going on and why this test is failing? My only thought is that including the debugger or irb somehow adds more support for UTF-8 but I'm at a loss to figure out where to go next.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby