Capybara提交按钮 - 不兼容的编码正则表达式匹配

时间:2011-04-10 20:54:02

标签: ruby-on-rails utf-8 rspec capybara

form.erb

<%= form_for @search do |f| %>
  <%= f.text_field :name %>
  <%= f.submit 'submit' %>
<% end %>

searches_spec.rb

require 'spec_helper'

describe SearchesController do 
  it "should do something" do
    visit searches_path

    page.fill_in 'search_name', :with => 'oak'

    click_button 'submit'
  end
end

输出

Failure/Error: click_button 'submit'
 Encoding::CompatibilityError:
   incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)
 # ./spec/integration/searches_spec.rb:16:in `block (2 levels) in <top (required)>'

尝试在Capybara中简单地提交表单,但收到此错误。有什么想法吗?

rails 3.1,capybara 0.4.1.2,rspec-rails 2.5.0

1 个答案:

答案 0 :(得分:2)

正如mculp在评论中指出的,这确实是mentioned bug in Rack

要暂时在本地修复它,请将以下内容放入spec_helper.rb或env.rb中以获取Cucumber(在Rack加载后的任何位置。)

module Rack::Utils
  def escape(s)
    CGI.escape(s.to_s)
  end
end