Cucumber和webrat - 如何处理paths.rb中的动态URL?

y0m*_*mbo 11 ruby-on-rails webrat cucumber

我在Ruby on Rails项目中使用Cucumber进行BDD开发,我对path.rb如何处理rails应用程序中使用的路径感到困惑.

鉴于我有:

class Parent < ActiveRecord::Base
  has_many :children
end

class Child < ActiveRecord::Base
  belongs_to :parent
end
Run Code Online (Sandbox Code Playgroud)

我有以下黄瓜功能:

Scenario: A test feature
    Given I am on the parent page
     When I follow "Link to Children"
     Then I should be on the children list page
Run Code Online (Sandbox Code Playgroud)

路径定义为:

def path_to(page_name)
  case page_name
  when /the children list page/
       '/parents/:id/children'
end
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是运行该功能时出现以下错误:

Spec::Expectations::ExpectationNotMetError: expected: "/parents/:id/children",
 got: "/parents/1726/children" (using ==)
Run Code Online (Sandbox Code Playgroud)

我真的不在乎:id是什么.我该怎么做呢?这是否可以使用默认的Web步骤?我是以错误的方式思考问题吗?

jon*_*nii 18

我这样做的方式可能不是最好的方法如下:

when /the children list page for "(.+)"/
    p = Parent.find_by_name($1)
    parent_children_path(p)
Run Code Online (Sandbox Code Playgroud)