【问题标题】:cucumber contradictory error messages黄瓜矛盾的错误信息
【发布时间】:2012-11-26 07:04:18
【问题描述】:

Problem Background: "cucumber declarative step definitions using web_steps.rb" Stack Overflow Question

在对有问题的问题进行故障排除时,出现了两条相互矛盾的错误消息;与声明:

When /^(?:|I )uncheck "([^"]*)"$/ do |field|
  check(field)
end

添加到 'features/step_definitions/movie_steps.rb' 执行 'bundle exec cucumber features/filter_movie_list.feature' 会导致:

Ambiguous match of "I uncheck "ratings_G"":

features/step_definitions/movie_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
features/step_definitions/web_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/

但是,删除步骤不会导致使用“web_steps.rb”中的步骤定义;而是显示不同的错误消息:

When I uncheck the following ratings: G, PG-13                 # features/step_definitions/movie_steps.rb:44
  Undefined step: "When I uncheck "ratings_G"" (Cucumber::Undefined)
  ./features/step_definitions/movie_steps.rb:52:in `block (2 levels) in <top (required)>'
  ./features/step_definitions/movie_steps.rb:49:in `each'
  ./features/step_definitions/movie_steps.rb:49:in `/I (un)?check the following ratings: (.*)/'
  features/filter_movie_list.feature:30:in `When I uncheck the following ratings: G, PG-13'

当两个地方有两个定义时,Cucumber 怎么可能抱怨一个步骤是多余的,但后来又抱怨删除重复的步骤时没有定义相同的步骤?是否有可能第二条错误消息真的意味着不同于所述内容?

PS:配置是通过 Cucumber 安装完成的,带有 CS169.x1 @ edX 的训练轮...

【问题讨论】:

    标签: ruby-on-rails ruby cucumber


    【解决方案1】:

    您似乎有一个名为When I uncheck "ratings_G" 的定义与错误消息中出现的调用When I uncheck the following ratings: G, P-13 有点匹配。 Cucumber 抱怨没有什么比得上后者。它存在于您的代码中吗?

    有点匹配可能会解释您最初收到的歧义警告。定义匹配,但与字符串中的内容不匹配。

    【讨论】:

    • 不...这是一个很好的猜测,但是如果您检查帖子开头的“问题背景”链接,您可以看到“以下评级”步骤是声明性的,并通过重用实现步骤(因此不能使上述问题更加原子化);问题是为什么 web_steps.rb 步骤没有被重用,因为配置似乎允许尽可能多的......
    • hmmm - 是的 - 我在那里输入了错误的轨道。 movie_steps 中步骤定义的顺序是否相关?如果“未定义”步骤在“收集”步骤之后,它可能不可见?也许是牵强附会……
    • 好吧,似乎向上移动“当我取消选中”语句没有太大影响:将它留在文件中(在声明性步骤的实现之上)会导致“模糊匹配“ 错误;删除它会导致“未定义的步骤”...
    • 您确定您的 web_steps.rb 在范围内可见吗?猜测是在movie_steps.rb 中的两种取消选中之间存在歧义,而web_steps.rb 根本不可见。尝试将When I uncheck the following ratings 改写为When unchecking the following ratings 之类的不同名称,看看是否可行。 (我以前见过这个,我怀疑这种行为在黄瓜版本之间发生了变化。)
    • 非常好的弗罗德里克!我试图使声明性步骤尽可能自然的努力应该考虑到我已经知道的,即 RegEx 只能匹配一个模式,而复制一个模式会造成混乱......在这种情况下,框架的框架问题(“创建类似步骤”的一些指示)可能让我失望......
    猜你喜欢
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 2018-03-11
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多