黄瓜测试顺序的元素在表中

Sor*_*ami 8 ruby bdd ruby-on-rails cucumber

我想运行一个测试,测试我希望订单按日期升序的元素的顺序.

这是我的黄瓜功能场景和最后一句的步骤.

Scenario: Order of the events should be Ascending
    Given I am signed into an account called "Gorilla Tech" as a customer
    When I follow "Register"
    And I follow "Events"
    And I follow "Register new event"
    Then I should see the header "Use the form below to register a new event"
    And I fill in "Title" with "Apefest 2010"
    And I fill in "Event at" with "2010-01-07"
    And I fill in "Add a note" with "This was truly awesome"
    Then I press "Create"
    Then I follow "Register new event"
    And I fill in "Title" with "Monkeyfest 2010"
    And I fill in "Event at" with "2010-01-08"
    And I fill in "Add a note" with "Yeah"
    Then "Apefest 2010" should appear before "Monkeyfest 2010"



   Then /"(.*)" should appear before "(.*)"/ do |first_example, second_example|
     response.body.should =~ /#{first_example}.*#{second_example}/
   end
Run Code Online (Sandbox Code Playgroud)

我这里真的有两个问题.第一个是如何正确指定我的测试?我可以将上面的测试指定为不同且更正确吗?

我想要做的是在2个不同的日期注册2个不同的事件.该事件稍后将显示为网页上的列表.然后我想检查事件是否按日期排序.我希望最新日期的活动显示在顶部.

这是我要测试的集合的代码.在某种程度上,我想检查下面div中的集合是否按日期升序.

<div id="feeds">
    <table>
      <caption><%= t('events.all') %></caption>
      <thead>
        <tr>
          <th><%= Event.t(:title) %></th>
          <th><%= Event.t(:event_at) %></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <%= render :partial => 'event', :collection => @events %>
      </tbody>
    </table>
  </div>

  <%= will_paginate(@events) %>
Run Code Online (Sandbox Code Playgroud)

And*_*rra 13

您编写步骤定义的方式很好,您只需要将多行(m)开关添加到您的模式中.:)

response.body.should =~ /#{first_item}.*#{second_item}/m
Run Code Online (Sandbox Code Playgroud)

  • 你在黄瓜后面使用水豚或网络吗?如果水豚你会使用'page'而不是'response',你可能需要也可能不需要调用body方法.如果webrat应该可以工作,除非你还没有真正访问过一个页面. (3认同)
  • page.body.should是你需要的水豚. (2认同)