Ruby on rails 3 选择多个复选框

Ruby on rails 3 选择多个复选框,ruby-on-rails-3,cucumber,Ruby On Rails 3,Cucumber,我正在使用Cucumber 1.1.1开发Rails 3应用程序,并尝试在Cucumber场景中选择多个复选框 以下是我在haml中的多个复选框: - for diocese in Diocese.all = check_box_tag "clergy[diocese_ids][]", diocese.id, @clergy.dioceses.include?(diocese) = f.label diocese.name %br 这是我的黄瓜步骤 When /^I check

我正在使用Cucumber 1.1.1开发Rails 3应用程序,并尝试在Cucumber场景中选择多个复选框

以下是我在haml中的多个复选框:

- for diocese in Diocese.all
  = check_box_tag "clergy[diocese_ids][]", diocese.id, @clergy.dioceses.include?(diocese)
  = f.label diocese.name
  %br 
这是我的黄瓜步骤

When /^I check the (\d+)(st|nd|rd|th) of the "([^"]*)" checkboxes$/ do |index, junk, group|
  page.all("input[id=\"clergy_diocese_ids_\"]")[index.to_i - 1].check('clergy_diocese_ids_') 
end
这是我的黄瓜测试:

  @wip
  Scenario: New Clergy
    Given I am on the clergies page
    When I follow "New Clergy"
    And I fill in "Surname" with "Wells"
    And I fill in "Given names" with "Robin"
    And I check the 1st of the "diocese" checkboxes
    And I check the 2nd of the "diocese" checkboxes
    And I press "Create Clergy"
    Then I should see "Clergy was successfully created."
运行测试时出现的错误:

    And I check the 1st of the "diocese" checkboxes                                    # fea
tures/step_definitions/clergy_steps.rb:37                                                  
      cannot check field, no checkbox with id, name, or label 'clergy_diocese_ids_' found (C
apybara::ElementNotFound)                                                                  
      ./features/step_definitions/clergy_steps.rb:38:in `/^I check the (\d+)(st|nd|rd|th) of
 the "([^"]*)" checkboxes$/'                                                               
      features/clergy_new.feature:17:in `And I check the 1st of the "diocese" checkboxes'

我尝试过在页面上玩。所有选择器都是,但我无法解决它。

据我所知,Cucumber的工作不是选择复选框并与UI交互。Cucumber解析特征文件并执行匹配的相应步骤定义。每个步骤定义块中的内容由您决定


由于您的步骤定义代码似乎使用了水豚,我建议查看。

您是否检查了呈现的页面输出以检查复选框上id属性的格式?是的,我使用firefox下的firebug检查了我的复选框id。从Cumber步骤的外观来看,您的测试似乎希望所有复选框共享相同的id。是否需要使用字符串插值来形成需要选择的复选框的正确ID?