cucumber / aruba

Test command-line applications with Cucumber-Ruby, RSpec or Minitest.
MIT License
949 stars 163 forks source link

Undefined method `[]' for nil:NilClass (NoMethodError) #168

Closed eduardomello closed 10 years ago

eduardomello commented 10 years ago

I just started using cucumber and I have a scenario that is trying to use the

Then ^the output from "([^"]*)" should contain "([^"]*)"$/

clause like this

And the output from "git checkout some-branch" should contain "Switched to branch 'some-branch'"

When i run the tests I end up receiving this error message:

aruba-0.5.3/lib/aruba/cucumber.rb:101 undefined method []' for nil:NilClass (NoMethodError) features/pm_creates_metabranch.feature:21:inAnd the output from "git checkout some-branch" should contain "Switched to branch 'some-branch'"'

What's wrong here?

Running Ruby 2.0.0-p247

jarl-dk commented 10 years ago

Two things:

  1. You have discovered that aruba is not robust against commands that don't output anything. I will look at this.
  2. It seems like git is not outputing anything, maybe because it is not run interactively...
jarl-dk commented 10 years ago

No wait....

It is not enough to only have

And the output from "git checkout some-branch" should contain "Switched to branch 'some-branch'"

That step will only validate.

You must have something like:

When I run "git checkout some-branch"
And the output from "git checkout some-branch" should contain "Switched to branch 'some-branch'"

The first one executes the command, the second one verifies the output.

That should do it...

Please confirm and I will close.

eduardomello commented 10 years ago

I end up doing

And I run `git checkout some-branch`
And the output should contain "Switched to branch 'some-branch'"

Doesn't it make the

And the output from "[cmd]" should contain "[something]"

kind of useless?

jarl-dk commented 10 years ago

The value of And the output from "[cmd]" should contain "[something]" is that you can run several independent process in same scenario. Then you can use the above to refer to which process you are validating the output from. for example:

And I run `git checkout some-branch`
And I run 'printf "hello"`
And the output should contain "Switched to branch 'some-branch'"

Will fail because the last one will compare all output from all the commands, but using And the output from "[cmd]" should contain "[something]" you can specify which process you compare the output from.

Anyway your report illustrates that the documentation seems insufficient. Thank you.