加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 黄瓜和/或Webrat讨厌?

发布时间:2020-12-17 03:11:18 所属栏目:百科 来源:网络整理
导读:我有一个黄瓜步骤,最近开始失败,当 nbsp;被添加到我的布局中.如果我带 nbsp;我的测试都通过了.当我把它重新放入时,每个使用WebRat提供的click_link方法的测试都会失败,并显示以下消息: And he follows 'Unsubscribe' incompatible encoding regexp match (U
我有一个黄瓜步骤,最近开始失败,当& nbsp;被添加到我的布局中.如果我带& nbsp;我的测试都通过了.当我把它重新放入时,每个使用WebRat提供的click_link方法的测试都会失败,并显示以下消息:

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''

有没有人有什么建议?

解决方法

我在Ruby 1.9和Rails 2.3.2下遇到了同样的问题,为了使它工作,我必须在webrat gem中进行以下更改.

在lib / webrat / core / locators / link_locator.rb中,我不得不改变:

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

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

还有一个补丁提交给webrat Ticket 260,但它对我不起作用,所以我不得不做上面的事情.希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读