1

由于路径.env 文件不是为 Cucumber 1.1+ 生成的,例如,如果我visit login_path经常在测试步骤中使用,我应该为它创建一个单独的步骤还是应该在visit login_path任何地方使用?如果它发生变化,我可以轻松地在 features 目录下进行字符串替换。

谢谢!

4

1 回答 1

0

如果这真的只是把你的电话弄干的问题,visit login_path我会留下它们,因为它们清晰简洁,而且你(可能)不需要更改登录路径帮助程序。

但是,如果您开始看到像这样稍微复杂的步骤,

# in features/step_definitions/profile_steps.rb

When /^I go to my profile$/ do
  visit user_path(@current_user)
end

考虑使用paths.rb模型:

# in features/step_definitions/common_steps.rb

Given /^I go to (.+)$/ do |page_name|
  visit path_to(page_name)
end

# in features/support/paths.rb

module NavigationHelpers
  def path_to(page_name)
    when /my profile/
      user_path(@current_user)
    ...
  end
end
World(NavigationHelpers)

That's right, I like paths.rb and selectors.rb and copy them to new projects :) I am glad to see the "kitchen sink" web_steps.rb go though. For examples of how I use the support files: https://github.com/coshx/green-eggs/blob/master/features/support

于 2012-05-15T06:44:24.973 回答