5

为了将 Cucumber 用于命令行脚本,我按照提供的说明安装了 aruba gem。它在我的 Gemfile 中,我可以验证是否安装了正确的版本并且我已经包含

require 'aruba/cucumber'

在“功能/env.rb”中

为了确保它有效,我编写了以下场景:

@announce
Scenario: Testing cucumber/aruba
    Given a blank slate
Then the output from "ls -la" should contain "drw"

假设事情应该失败。

它确实失败了,但由于错误的原因而失败:

@announce
Scenario: Testing cucumber/aruba                 
    Given a blank slate                        
    Then the output from "ls -la" should contain "drw"
        You have a nil object when you didn't expect it!
        You might have expected an instance of Array.
        The error occurred while evaluating nil.[] (NoMethodError)
        features/dataloader.feature:9:in `Then the output from "ls -la" should contain "drw"'

任何人都知道为什么这不起作用?这似乎是非常基本的阿鲁巴行为。

4

1 回答 1

8

您缺少“何时”步骤 - aruba“输出应包含”步骤要求该命令已经运行(它本身不会运行它,它只是查找它)。

@announce
Scenario: Testing cucumber/aruba
    Given a blank slate
    When I run `ls -la`
    Then the output from "ls -la" should contain "drw"

这在我的机器上产生:

@announce
Scenario: Testing cucumber/aruba                     # features/test_aruba.feature:8
    When I run `ls -la`                                # aruba-0.4.11/lib/aruba/cucumber.rb:56
      $ cd /Users/d.chetlin/dev/mine/ladder/tmp/aruba
      $ ls -la
      total 0
      drwx------  2 d.chetlin  staff   68 Feb 15 23:38 .
      drwx------  7 d.chetlin  staff  238 Feb 15 23:38 ..

    Then the output from "ls -la" should contain "drw" # aruba-0.4.11/lib/aruba/cucumber.rb:86

1 scenario (1 passed)
2 steps (2 passed)
0m0.465s
于 2012-02-16T04:41:37.403 回答