在测试驱动开发中使用Rspec和Cucumber解释错误

时间:2012-06-23 12:22:38

标签: ruby-on-rails rspec cucumber

我是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

所以我回到我的黄瓜特色:

  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 (.+)$/'

我是否需要在视图中完成路线?我是否需要编写一个不明确的步骤定义?我不知道如何从这里开始,任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

我的猜测是你需要完成你创建的link_to方法。 Cucumber进行高级测试,因此它会点击该链接并关注它。由于您尚未指定路径,因此可能会将您保留在当前页面,而不是将您带到“相似项目”页面。