2009-08-12 66 views
5

我有一個黃瓜步,最近開始失敗時, 被添加到我的佈局。如果我拿出 ,我的測試全部通過。當我把它放回,使用由WebRat提供的click_link方法每個測試失敗,出現以下消息:黃瓜和/或Webrat仇恨 ?

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

有沒有人有什麼建議?

回答

5

我在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(/\xc2\xa0/u, ' ') 
    else 
    str.gsub(/\xc2\xa0/u, ' ') 
    end 
end 

還有submited到webrat Ticket 260一個補丁,但它並沒有爲我工作,所以我不得不做上述。希望這可以幫助。