检查“命令”的输出应该包含 NilClass 的意外崩溃

发布于 2025-01-06 01:57:34 字数 884 浏览 4 评论 0原文

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

require 'aruba/cucumber'

在“features/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"'

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

In an effort to use Cucumber for a command-line script, I've installed the aruba gem as per the instructions provided. It's in my Gemfile, I can verify that the correct version is installed and I've included

require 'aruba/cucumber'

in 'features/env.rb'

In order to ensure it works, I wrote the following scenario:

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

assuming the thing should fail.

It does fail, but it fails for the wrong reasons:

@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"'

Anyone have any ideas why this isn't working? This seems to be very basic aruba behavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2025-01-13 01:57:34

您缺少“何时”步骤 - 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

You are missing a 'When' step - the aruba "output should contain" step requires the command to have already run (it does not run it itself, it only looks it up).

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

This produces, on my machine:

@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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文