ruby-on-rails – 如何为“编辑”路径创建Cucumber步骤定义?
发布时间:2020-12-17 04:05:46 所属栏目:百科 来源:网络整理
导读:我正在尝试学习如何使用Cucumber并使用以下场景创建步骤(我有一个名为“Vegetable”的模型,并且我添加了一个名为“color”的新属性): Scenario: add color to existing vegetable When I go to the edit page for "Potato" And I fill in "Color" with "Bro
我正在尝试学习如何使用Cucumber并使用以下场景创建步骤(我有一个名为“Vegetable”的模型,并且我添加了一个名为“color”的新属性):
Scenario: add color to existing vegetable When I go to the edit page for "Potato" And I fill in "Color" with "Brown" And I press "Update Vegetable Info" Then the color of "Potato" should be "Brown" 我目前正在使用“训练轮”,所以我有一个网页步骤(web_steps.rb): When /^(?:|I )go to (.+)?/ do |page_name| visit path_to(page_name) end 现在我了解这是如何工作的简单页面导航,如“当我去蔬菜主页.”我所要做的就是添加paths.rb的路径: When /^the vegetable home page/ '/vegetables' 但是,通过上面的例子,我需要使用特定的蔬菜“/ vegetables / 1”(Potato url)去特定的路径. 我不知道该怎么做,所以我尝试创建了自己的步骤: When /I go to the edit page for "(.*)"/ do |vegetable_name| flunk "Unimplemented" end 但我得到错误: Ambiguous match of "I go to the edit page for "Potato"": features/step_definitions/vegetable_steps.rb:15:in `/go to the edit page for "(.*)"/' features/step_definitions/web_steps.rb:48:in `/^(?:|I )go to (.+)$/' You can run again with --guess to make Cucumber be more smart about it (Cucumber::Ambiguous) 这是我应该这样做的吗?或者我只是使用web_steps“转到”步骤并在paths.rb文件中以某种方式提供id?我只想弄清楚如何在阅读各种Cucumber教程后开始这个. 解决方法
正如DVG所说,这是因为我在两个地方进行了匹配步骤,我收到了错误.要回答我自己的问题,我可以依靠已经提供的“web_step”:
When /^(?:|I )go to (.+)?/ do |page_name| visit path_to(page_name) end 一旦我将以下代码添加到paths.rb: def path_to(page_name) case page_name when /^the edit page for "(.*)"$/ edit_vegetable_path(Vegetable.find_by_name($1)) 我能够让它正常工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |