“耙子"运行我所有的黄瓜测试都很好,但“黄瓜"没有步骤 [英] "rake" runs all my Cucumber tests fine but "cucumber" doesn't have the steps

查看:13
本文介绍了“耙子"运行我所有的黄瓜测试都很好,但“黄瓜"没有步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了 Rails (3) 应用程序,并试图掌握现有的 Cucumber 测试.我在应用程序的功能"文件夹中有以下设置(我错过了任何不相关的文件,例如额外的功能和步骤)

I've inherited a Rails (3) app and am trying to get to grips with the existing Cucumber tests. I've got the following setup in the app's 'features' folder (I've missed out any files which aren't relevant, eg extra features and steps)

/features
  /people
    new-person.feature
  /step_definitions
    people_steps.rb
    web_steps.rb
  /support
    env.rb
    paths.rb
    selectors.rb

如果我运行rake",那么它将运行 features/people/new-person.feature 中的所有功能,并正确使用 step_definitions 中列出的步骤.

If I run 'rake' then it runs all the features in features/people/new-person.feature, correctly using the steps listed in step_definitions.

但是,我不想每次都运行 rake,因为它需要太长时间,我只想在 Cucumber 中运行一个特定的测试,例如黄瓜特征/people/new-person.feature -l 8

However, I don't want to run rake every time as it takes too long, I just want to run a specific test in Cucumber, e.g. cucumber features/people/new-person.feature -l 8

当我这样做时,它会运行该功能但尚未加载步骤.我回来了:

When I do this, it runs the feature but hasn't loaded the steps. I get this back:

Using the default profile...
Feature: Add a new person
  In order to allocate tasks to people
  As a community manager
  I want to add a new person

  Scenario: Secondary navigation should contain "Add new person" # features/people/new-person.feature:8
    Given I am on the new person page                            # features/people/new-person.feature:9
      Undefined step: "I am on the new person page" (Cucumber::Undefined)
      features/people/new-person.feature:9:in `Given I am on the new person page'
    Then I should not see "Add new person"                       # features/people/new-person.feature:10
      Undefined step: "I should not see "Add new person"" (Cucumber::Undefined)
      features/people/new-person.feature:10:in `Then I should not see "Add new person"'

1 scenario (1 undefined)
2 steps (2 undefined)
0m0.005s

You can implement step definitions for undefined steps with these snippets:

Given /^I am on the new person page$/ do
  pending # express the regexp above with the code you wish you had
end

Then /^I should not see "([^"]*)"$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

If you want snippets in a different programming language, just make sure a file
with the appropriate file extension exists where cucumber looks for step definitions.

为什么 Cucumber 不加载步骤?我猜我需要在某处要求这些步骤,但我不知道在哪里.

Why isn't Cucumber loading the steps in? I'm guessing that I need to require the steps somewhere but I can't work out where.

谢谢,马克斯

推荐答案

Max Williams 找到了他的问题的答案:

Max Williams found the answer to his question:

编辑 - 在这里找到答案:https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories

EDIT - found the answer, here: https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories

在 config/cucumber.yml 中有一行如下所示:

In config/cucumber.yml there's a line that looks like this:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"

改成

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"

这就像在你的黄瓜测试运行结束时添加 --require features/ 并使其正确加载所有内容.

This is like adding --require features/ to the end of your cucumber test run and makes it load everything up properly.

这篇关于“耙子"运行我所有的黄瓜测试都很好,但“黄瓜"没有步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆