无法确定导致黄瓜测试失败的原因是什么?

时间:2019-01-30 21:44:59

标签: html ruby-on-rails ruby cucumber

我将一些Ruby代码转换为HTML,因此可以使用Bootstrap,但是现在它告诉我它并没有到达正确的页面-而是。

失败表明它到达/ create_exercise路径,但是当我运行RoR应用程序时,当我在页面上提交表单时(使用commit_tag“ Enter”按钮),它的确进入/ create_workout路径。 。尝试将该行切换为Ruby代码,但仍然失败,因此不是提交按钮。

这是黄瓜故障:

Scenario: I enter a new exercise                   # features/create_exercise.feature:15
    Given I login and am on the create exercise page # features/step_definitions/generic_steps.rb:76
    When I enter "Sit ups" into "name"               # features/step_definitions/generic_steps.rb:131
    And I choose "Cardio"                            # features/step_definitions/generic_steps.rb:119
    And I press "Enter"                              # features/step_definitions/generic_steps.rb:113
    Then I should be on the create workout page      # features/step_definitions/generic_steps.rb:82
      current_path: /create_exercise
      should_path: /create_workout
      expected: "/create_workout"
           got: "/create_exercise" (using ==) (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/generic_steps.rb:87:in `/^(?:|I )should be on (.+)$/'
      features/create_exercise.feature:21:in `Then I should be on the create workout page'
   (0.2ms)  rollback transaction

这是通过黄瓜测试的原始代码:

    <p>
  Create Exercise:<br />
  <%= form_tag process_create_exercise_path, :method => :post do %>
    <%= label_tag 'Name:' %>
    <%= text_field_tag 'name', '', :maxlength => 140, :autocomplete => 'off' %><br />
    <b>Category:</b><br />
    <%= radio_button_tag(:category, "Cardio") %>
    <%= label_tag(:cardio, "Cardio") %>
    <%= radio_button_tag(:category, "Strength") %>
    <%= label_tag(:strength, "Strength") %><br />
    <b>Everything below this is optional:</b><br />
    <%= label_tag 'Description:' %>
    <%= text_field_tag 'description', '', :maxlength => 140, :autocomplete => 'off' %><br />
    <%= label_tag 'Muscle Group:' %>
    <%= text_field_tag 'musclegroup', '', :maxlength => 140, :autocomplete => 'off' %><br />
    <%= submit_tag 'Enter' %>
  <% end %>
</p>

<%= render :template => 'homepage/template' %>

这是我的新代码(更漂亮),但导致上述失败:

<html>
<body>

  <legend>Create Exercise:</legend>

  <fieldset>
  <div class="form-group">
    <%= form_tag process_create_exercise_path, :method => :post do %>
      <label for="name">Name:</label>
      <input type="text" name="name" class="form-control" id="name" value="" maxlength="140" autocomplete="off" placeholder="Enter name of exercise">
  </div>

  <div class="form-group">
    <label for="category_select">Category:</label>
    <div class="form-check" id="category_select">
      <label class="form-check-label">
        <input type="radio" name="category" id="category_Cardio" value="Cardio" class="form-check-input">
        Cardio
      </label>
    </div>
    <div class="form-check">
      <label class="form-check-label">
        <input type="radio" name="category" id="category_Strength" value="Strength" class="form-check-input">
        Strength
      </label>
    </div>
  </div>

  <div class="form-group">
    <label for="description">Description:</label>
      <input type="text" name="description" id="description" value="" maxlength="140" autocomplete="off" placeholder="optional">
    <label for="muscle_group">Muscle Group:</label>
      <input type="text" name="muscle group" id="muscle_group" value="" maxlength="140" autocomplete="off" placeholder="optional">
    <!--<input class="btn btn-primary" type="submit" name="commit" value="Enter">-->
    <%= submit_tag "Enter" %>
  </div>

  <% end %>

  </fieldset>
</body>

<%= render :template => 'homepage/template' %>

</html>

1 个答案:

答案 0 :(得分:0)

没关系,我知道了。

以前是这一行:

<%= form_tag process_create_exercise_path, :method => :post do %>

...正在应用于整个表单,但是新版本仅将它包含在div中。将其移到div之外,并且可以正常工作。