【问题标题】:Tests, using Aruba with Rspec, failing with `run` is not available from within an example (e.g. an `it` block)测试,使用带有 Rspec 的 Aruba,在示例中无法使用“run”失败(例如,“it”块)
【发布时间】:2018-07-30 15:46:32
【问题描述】:

我需要使用 rspec 脚本测试控制台应用程序并检查打印输出。示例:

RSpec.describe 'Test Suite', type: :aruba do

  it "has aruba set up" do
    command = run("echo 'hello world'")
    stop_all_commands
    expect(command.output).to eq("hello world\n")
  end

它失败了:

Failure/Error: command = run("echo 'hello world'")
   `run` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).

Aruba 版本 0.14.6,Rspec 3.7.0。将不胜感激任何帮助。谢谢。

【问题讨论】:

  • run方法定义在哪里?
  • 根据文档 (rubydoc.info/github/cucumber/aruba/Aruba/Api/…),它应该是 run_command,但由于未知命令而失败。看起来 run 是这个版本的 Aruba::Api 的正确选择。文档是 w.......
  • "run 方法定义在哪里?" - 天知道.....在网上一无所获。 :(

标签: ruby rspec console-application aruba


【解决方案1】:

正如错误所暗示的,您不能在it 块内调用run。由于分支众多,Aruba 的文档在这里可能会有些混乱,但 run 方法仍然可以在 still 分支中使用,文档可以找到 here

按照文档,我们可以使用 let 在块外定义它,而不是在 it 块内定义 command

RSpec.describe 'Test Suite', type: :aruba do
  context "aruba test" do
    let(:command) { run("echo 'hello world'") }
    it "has aruba set up" do
      stop_all_commands
      expect(command.output).to eq("hello world\n")
    end
  end
end

【讨论】:

  • Failure/Error: stop_all_commands NameError: undefined local variable or method `stop_all_commands' for #<:examplegroups::....>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-16
  • 2021-10-31
相关资源
最近更新 更多