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

Ashley Moran work at ashleymoran.me.uk
Mon Feb 12 09:43:23 EST 2007


Not sure if this is more Rails or RSpec related...

I've got an app with an RJS view that updates a div in a page with  
the contents of a partial.  The partial contains a non-ascii  
character namely a pound sign.

I set up a simple test app with this RJS view:
     page.replace_html("test_div", :partial => "test_action")

and this _test_action.rhtml:

Now this spec fails:
     require File.dirname(__FILE__) + '/../../spec_helper'

     context "Given a request to render view_test/test_action" do
       setup do
         render 'view_test/test_action'

       specify "the response should have a p with £500" do
         response.should_have_tag 'p', :content => '£500'

       specify "the response should definitely have a p with £500" do
         response.should_have 'p', :text => '£500'

The error for the should_have_tag gives this error message:
     Element.update("test_div", "<p>\u00a3500</p>"); should include  
["[\"p\", {:content=>\"£500\"}]"]

I don't know, well, anything about JavaScript but I'm informed by one  
of our developers that the replacement string is in JSON format.   
Either way the only way to make the specs pass is to use :content  
(or :text) => '\u00a3500' which is completely different from the  
contents of the partial, so not a brilliant solution.  An alternative  
is to use &#163; for £, but that kinda defeats the point of using UTF8.

Any ideas how I can get round this?


More information about the rspec-users mailing list