简体   繁体   English

如何创建一个Cuke步骤定义,以测试仅可以肯定地显示结果?

[英]How to create a Cuke step definition that will test that only certainly results are displayed?

I've been searching high and low trying to implement a bunch of suggestions to crack this one, but none of them seem to work. 我一直在寻求高低的尝试,以实施一堆建议来破解这个建议,但是似乎没有一个可行。 Sorry if this has been answered elsewhere, I just couldn't find it! 抱歉,如果在其他地方都没有找到答案,我找不到它!

Basically, I'm stuck writing a step definition that tests that the current view has been filtered by certain criteria. 基本上,我坚持写一个步骤定义来测试当前视图是否已被某些条件过滤。 Here are the relevant steps: 以下是相关步骤:

  When I check the following ratings: PG, R
  And I uncheck the following ratings: G, PG-13, NC-17
  And I press "Refresh"
  Then I should see movies with the ratings: PG, R

And here are my step definitions for the latter two: 这是我对后两个步骤的定义:

And /I press "Refresh"/ do
    click_button("Refresh")
end

Then /I should see movies with the ratings: (.*)/ do |ratings|
    page.should have_content ratings
end

The first one straight up doesn't work (says it's ambiguous), and the second one says that it can't find the text PG, R on the page. 第一个直线向上不起作用(说得模棱两可),第二个直线则说找不到页面上的文本PG,R。 Cucumber is totally alien to me, and I am very lost! 黄瓜对我来说是完全陌生的,我很迷茫! Any advice you can offer would be greatly appreciated! 您可以提供的任何建议将不胜感激!

Edit: As requested, this is the Haml that Capybara is operating on: 编辑:根据要求,这是水豚在操作的Haml:

-#  This file is app/views/movies/index.html.haml
%h1 All Movies

= form_tag movies_path, :method => :get, :id => 'ratings_form' do
  = hidden_field_tag "title_sort", true if @title_header
  = hidden_field_tag ":release_date_sort", true if @date_header
  Include: 
  - @all_ratings.each do |rating|
    = rating
    = check_box_tag "ratings[#{rating}]", 1, @selected_ratings.include?(rating), :id => "ratings_#{rating}"
  = submit_tag 'Refresh', :id => 'ratings_submit'

%table#movies
  %thead
    %tr
      %th{:class => @title_header}= link_to 'Movie Title', movies_path(:sort => 'title', :ratings => @selected_ratings), :id => 'title_header'
      %th Rating
      %th{:class => @date_header}= link_to 'Release Date', movies_path(:sort => 'release_date', :ratings => @selected_ratings), :id => 'release_date_header'
      %th More Info
  %tbody
    - @movies.each do |movie|
      %tr
        %td= movie.title 
        %td= movie.rating
        %td= movie.release_date
        %td= link_to "More about #{movie.title}", movie_path(movie)

= link_to 'Add new movie', new_movie_path

Ambiguous means that you have a two same match so it doesn't know which one to use. 模糊意味着您有两个相同的匹配项,因此不知道要使用哪个匹配项。 In web-steps.rb you already have 在web-steps.rb中,您已经拥有

When /^(?:|I )press "([^"]*)"$/ do |button|
  click_button(button)
end

So you don't need to specify your own. 因此,您无需指定自己的名称。

You likely already have this step defined in step_definitions/browsing_steps.rb . 您可能已经在step_definitions/browsing_steps.rb定义了此步骤。

Delete your definition of And /I press "Refresh"/ 删除您对And /I press "Refresh"/的定义And /I press "Refresh"/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM