0

我正在结合使用 Cucumber、Webrat 和 Pickle。当我写一个场景时,我可以做这样的事情:

Given a product exists with title: "Bread"
When I go to the edit page for that product
And I fill in "Title" with "Milk"
And I press "Save changes"
Then I should see "Successfully edited product."
And I should be on that car's page

注意for that product. 这是 pickle 提供的东西,对于引用我正在检查其存在的产品的记录非常方便。但是,最后一行不起作用。

基本上我试图确保我是该记录的显示页面,但由于我没有它的 ID,我不知道如何引用它。

有什么帮助吗?谢谢!

4

1 回答 1

2

要引用创建的产品或其他任何内容,您可以使用 pickle 提供的命名:

Given product: "bread" exists with title: "Bread"
...
Then I should be on the showing page for the product "bread"

要处理此 url,您需要在 /features/support/paths.rb 中添加几行:

  when %r{^the showing page for the (.+)$}
    polymorphic_path(model($1))

像这样处理模型的编辑路径也可能很有用:

Then I should be on the edit page for the product "bread"

路径.rb:

  when %r{^the edit page for the (.+)$}
    polymorphic_path(model($1), :action => 'edit')
于 2010-06-23T08:11:33.803 回答