【问题标题】:Then I should not see (Cucumber)那我不应该看到(黄瓜)
【发布时间】:2012-10-26 22:40:17
【问题描述】:

我正在尝试使用 Cucumber 检查网页上的过滤器功能。如果我检查特定的电影评级,那么它应该只显示表中具有这些评级的电影。这是我的场景:

When I check the following ratings: 'PG', 'R'
And I press Refresh
Then I should not see /PG/

这是我的步骤定义:

Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
  regexp = Regexp.new(regexp)
  if page.respond_to? :should
    page.should have_no_xpath('//*', :text => regexp)
  else
    assert page.has_no_xpath?('//*', :text => regexp)
  end
end

但我收到“不明确的匹配”错误。

这里是一些 HTML,以防它很重要:

  <table id='movies'>
    <thead>
      <tr>
        <th>Movie Title</th>
        <th>Rating</th>
        <th>Release Date</th>
        <th>More Info</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Aladdin</td>
        <td>G</td>
        <td>1992-11-25 00:00:00 UTC</td>
        <td><a href="/movies/1">More about Aladdin</a></td>
      </tr>

谢谢!

【问题讨论】:

  • 有史以来最好的标题。

标签: ruby-on-rails cucumber


【解决方案1】:

问题不在于您在此处定义的步骤,而在于您在其他地方定义了与其中之一冲突的步骤。如果此处有意义,您应该重用该步骤,或者创建一个不冲突的步骤。

【讨论】:

    【解决方案2】:

    正如 michaeltwofish 所说。您可能定义了一个执行相同操作的步骤。尝试删除其中一个步骤。

    如果您有重复的方法/定义。意思是一个带有“And”的定义和另一个带有“Then”的定义,它们做同样的事情算作同样的方法。

    And/When/Then/Given 基本上是一回事。他们服务只是为了让用户故事流在一个更具可读性的庄园中

    希望这些附加信息有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多