我是 Rails 和 TDD 的新手,并且被困在 Rspec 测试和 Cucumber 测试之间的过渡中。我的 Rspec 测试全部通过绿色:
ModelController
Find with same attribute
should call the controller method that performs attribute search
should select the Search Results template for rendering
should make the attribute search results available to that template
所以我回到我的 Cucumber 功能:
When I follow "Find Items With Same Attribute"
Then I should be on the Similar Items page for "Attribute"
如果我将其包含在我的视图中,则第一个变为绿色:
= link_to "Find Items With Same Attribute"
对于第二个,我修改了我的 paths.rb 文件以包含:
when /^the Similar Items page for "(.*)"/
"/model/search_by_attribute/#{Model.find_by_name($1).attribute}"
然后它失败并出现此错误
expected: "/model/search_by_attribute/Attribute"
got: "/model/1" (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:233:in `/^(?:|I )should be on (.+)$/'
features/search_by_attribute.feature:25:...
如果我在 model_steps.rb 中包含一个步骤定义,我会得到一个不同的错误:
Ambiguous match of "I should be on the Similar Items page for "Attribute"":
features/step_definitions/model_steps.rb:11:in `/^(?:|I )should be on the (.+) page for "(.*)"$/'
features/step_definitions/web_steps.rb:230:in `/^(?:|I )should be on (.+)$/'
我需要在视图中完成路线吗?我是否需要编写一个不会模棱两可的步骤定义?我不知道如何从这里开始,任何建议将不胜感激。