follow me icons

Monday, July 18, 2011

cucumber - undefined method `line' for nil:NilClass (NoMethodError)

This error occurs when I run my cucumber test using the tag:

e.g
/test>bundle exec cucumber features\regression\simple_test -t @test

undefined method `line' for nil:NilClass (NoMethodError)
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/formatter/filter_formatter.rb:64:in `examples'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/formatter/tag_count_formatter.rb:30:in `examples'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/listener/formatter_listener.rb:107:in `replay_step_or_examp
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/listener/formatter_listener.rb:41:in `scenario_outline'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:46:in `__send__'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:46:in `method_missing'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:31:in `parse'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/feature_file.rb:35:in `parse'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:28:in `load'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:26:in `each'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:26:in `load'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:14:in `features'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime.rb:132:in `features'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime.rb:45:in `run!'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/cucumber:14
/test/vendor/ruby/1.8/bin/cucumber:19:in `load'
/test/vendor/ruby/1.8/bin/cucumber:19

It turns out that cucumber (0.10) is not able to handle an empty scenario outline.
e.g

@test
Scenario Outline: An Empty scenario outline example - Add Two Number
Given I have entered <num_1> into the calculator
And I press add
And I have entered <num_2> into the calculator
When I press add
Then the result <result> should be on the screen
Examples:
|num_1 | num_2 | result |

The reason I have an empty scenario outline is for a placeholder.

If you run the cucumber without using the tag (e.g bundle exec cucumber features\regression\simple_test), then cucumber will run just fine.

The fix is to just add examples into scenario outline or to comment out the scenarios.

1 comment: