Mat*_*nde 5 ruby-on-rails webrat cucumber
我有一个黄瓜步骤,最近 在添加到我的布局时失败了.如果我拿出 来,我的测试全部通过.当我把它重新放入时,每个使用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''
Run Code Online (Sandbox Code Playgroud)
有没有人有什么建议?
我在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
Run Code Online (Sandbox Code Playgroud)
至
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
Run Code Online (Sandbox Code Playgroud)
还有一个补丁提交给webrat Ticket 260,但它对我不起作用所以我不得不做以上操作.希望这可以帮助.