0

在我的 support/paths.rb 文件中,我的 case 子句之一是:

when /the checkout page/ then '/store/checkout'

但是,在某些流程中,到结帐页面的重定向会向 URL 添加一些参数,因此重定向不是到“/store/checkout”而是到(例如)“/store/checkout?email_confirmation=1”。

问题是这会导致 Cucumber 的一些断言失败,例如下面的第 3 行:

Given I am on the checkout page
When I proceed with a blank email address
Then I should be on the checkout page
And I should see "You must provide an email address."

第 3 步失败:

   Then I should be on the checkout page                              # features/step_definitions/web_steps.rb:185
  expected: "/store/checkout",
       got: "/store/checkout?email_confirmation=1" (using ==)

如何让 Cucumber 忽略“?”之后的参数?在重定向的 URL 中?

Then I should be on the checkout page

4

2 回答 2

0

我听从了 Geoff 的建议,通过修改 web_steps.rb 解决了这个问题。具体来说,在固定步骤定义中

Then /^(?:|I )should be on (.+)$/ do |page_name|

我改变了这个断言

current_path.should == path_to(page_name)

对此,它只比较任何 '?...' 参数字符串之前的 URL 部分:

current_path.gsub(/\?.*$/, '').should == path_to(page_name).gsub(/\?.*$/, '')
于 2013-01-20T19:52:56.323 回答
0

对于后代,答案(在评论中很深)是执行以下操作之一:

  1. 更新到cucumber-rails-training-wheels包含预期行为的新内容。

  2. 确保web_steps.rb正确设置current_path变量。

    current_path = URI.parse(current_url).path
    

    而不是这个:

    current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
    
于 2013-01-21T22:55:01.777 回答