Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber and/or Webrat hates  ?

Tags:

I have a cucumber step that recently started failing when an   was added to my layout. If I take the   out, my tests all pass. When I put it back in, every test that uses the click_link method supplied by WebRat fails with the following message:

And he follows 'Unsubscribe'
  incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string) (Encoding::CompatibilityError)
  (eval):3:in `click_link`
  (eval):2:in `click_link`
  /path_to_project/webrat_steps.rb:19:in `/^(I|he|she) follows? '([^\"]*)'$/'
  features/manage_subscriptions.feature:59:in `And he follows 'Unsubscribe''

Does anyone have any suggestions?

like image 907
Matt Grande Avatar asked Aug 12 '09 19:08

Matt Grande


1 Answers

I had the same problem under Ruby 1.9 and Rails 2.3.2, in order to get it working I had to make the following changes in the webrat gem.

In lib/webrat/core/locators/link_locator.rb I had to change:

def replace_nbsp(str)
  str.gsub([0xA0].pack('U'), ' ')
end

to

def replace_nbsp(str)
  if str.respond_to?(:valid_encoding?)
    str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
  else
    str.gsub(/\xc2\xa0/u, ' ')
  end
end

There was also a patch submited to webrat Ticket 260, but it did not work for me so I had to do the above. Hope this helps.

like image 108
Bart Jedrocha Avatar answered Oct 02 '22 13:10

Bart Jedrocha