Tests, using Aruba with Rspec, failing with `run` is not available from within an example (e.g. an `it` block)

428 Views Asked by At

I need to test a console application and check printed output, using rspec script. Example:

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

It fails with:

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 version 0.14.6, Rspec 3.7.0. Will appreciate any help. Thanks.

1

There are 1 best solutions below

1
On

As the error implies, you cannot call run within the it block. Aruba's documentation can get a bit confusing here because of the various branches, but the run method is still available in the still branch, with documentation found here.

Following the documentation, instead of defining command within the it block, we can instead define it outside the block using let:

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