[rspec-users] Specs for Ajax partials with unicode characters

Ashley Moran work at ashleymoran.me.uk
Thu Feb 15 13:02:56 EST 2007


On 15 Feb 2007, at 16:49, David Chelimsky wrote:

> Yes - looks like json does that transformation. My feeling is that you
> should probably use '\u00a3500' and that's OK. The reality is that is
> what shows up in the response.
>
> WDYT?


Eventually I decided to do
   js_pound_sign = '\u00a3'

and test for
   js_pound_sign + '500'

This works for me.  On the one hand, I agree that it makes sense to  
test the output that is actually rendered.  On the other hand, it's  
counter-intuitive to have a partial containing "łączność" (or so  
my Polish colleague tells me) and test for "\u0142\u0105czno\u015b 
\u0107".

The Rails file activesupport/lib/json/encoders/core.rb only contains  
a JSON string ENcoder, but I assume the decoding is straightforward  
enough.  What would be nice is something like

context "my view"
   setup do
     render "moo/quack", :json_to_utf8 => true
   end

   ... specs all receive UTF8 strings ...
end

I don't know if it's worth the effort right now though, seeing as you  
probably can just put dummy text in for most stuff that would need  
UTF8 characters.  Non-English speakers will probably disagree :)

Ashley


More information about the rspec-users mailing list