已找到水豚 select_option,但未选中

Capybara select_option is found, but not selected

我正在尝试使用 Capybara Select Method. I tried all the solutions included, especially those from this Whosebug Discussion

我用 country_select gem 完成了以下 select。这是来自以下形式的 html.erb 代码:

<%= f.country_select(:country, {include_blank: 'Select a country', selected: "Select a country"}, {class: 'form-control', :id => "country_select"}) %>

来自浏览器的 html 看起来像这样:

<select class="form-control" id="country_select" name="user[country]"><option value="">Select a country</option>
    <option value="AF">Afghanistan</option>
    <option value="AX">Åland Islands</option>
    <option value="AL">Albania</option>
    other staff...

当我从 Capybara GEM file actions.rb row 183 调试 select 方法时(我设置了一个断点),输出是正确的。

  def select(value, options={})
    binding.pry
    if options.has_key?(:from)
      from = options.delete(:from)
      find(:select, from, options).find(:option, value, options).select_option
    else
      find(:option, value, options).select_option
    end
  end

所以行:

find(:select, from, options).find(:option, value, options)

returns

=> #<Capybara::Node::Element tag="option" path="/html/body/div/div[2]/div/div/div/div/div/form/div[4]/select/option[2]">

哪个是正确的 select 选项。如您所见,option[2] 是阿富汗,但看起来 .select_option 不起作用。

我认为 Capybara 在 select 进入该领域之前没有打开 select 框。 我有水豚 (2.13.0) 和 rails 5.0.2

非常感谢 法布里齐奥·贝尔托利奥

谢谢。

我解决了这个问题。抱歉,这是一个愚蠢的解决方案。

我忘记在我的应用程序控制器中包含:

before_action :configure_permitted_parameters, if: :devise_controller?

https://github.com/plataformatec/devise#strong-parameters