[Cucumber] call the (Treetop?) parser directly?


#1

Cucumberists:

The sample code:

require ‘treetop’
require ‘cucumber’
require ‘cucumber/parser’
require ‘cucumber/parser/treetop_ext’

too many requires because fishing around!

include Cucumber
include Parser
include Feature

@parser = FeatureParser.new
exp = @parser.parse_or_fail(%{# My comment
Feature: hi
})

The error message:

NameError: undefined local variable or method
_nt_scenario_outline_keyword' for #<Cucumber::Parser::FeatureParser:0xb6f3f67c> cucumber (0.3.0) lib/cucumber/parser/feature.rb:855:in_nt_scenario_outline’
cucumber (0.3.0) lib/cucumber/parser/feature.rb:106:in
_nt_feature' cucumber (0.3.0) lib/cucumber/parser/feature.rb:102:inloop’

Okay, how do I just whip out the parser and have it parse raw Cuke code?


Phlip
http://flea.sourceforge.net/resume.html


#2

On Sat, Apr 25, 2009 at 6:07 AM, Phlip removed_email_address@domain.invalid wrote:

include Cucumber
NameError: undefined local variable or method
_nt_scenario_outline_keyword' for #<Cucumber::Parser::FeatureParser:0xb6f3f67c> cucumber (0.3.0) lib/cucumber/parser/feature.rb:855:in_nt_scenario_outline’
cucumber (0.3.0) lib/cucumber/parser/feature.rb:106:in _nt_feature' cucumber (0.3.0) lib/cucumber/parser/feature.rb:102:inloop’

Okay, how do I just whip out the parser and have it parse raw Cuke code?

Try this:

require ‘cucumber’

Cucumber.load_language(‘en’)
p = Cucumber::Parser::FeatureParser.new
f = p.parse_or_fail <<-EOF
Feature: Foo
Scenario: Bar
Given Zap
EOF

Aslak


#3

aslak hellesoy wrote:

EOF

Aslak

Nope! Exact same error. Should I get the bench version? (It’s 0.3.0
now.)


Phlip
http://flea.sourceforge.net/resume.html


#4

Phlip wrote:

Scenario: Bar
Given Zap
EOF

Aslak

Nope! Exact same error. Should I get the bench version? (It’s 0.3.0 now.)

That sample works in a standalone script, and does not work in a Rails
unit test:

require File.dirname(FILE) + ‘/…/test_helper’

class CukeFeatureParser < ActiveSupport::TestCase

def test_parser

require ‘cucumber’

Cucumber.load_language(‘en’)
p = Cucumber::Parser::FeatureParser.new
f = p.parse_or_fail <<-EOF
Feature: Foo
Scenario: Bar
Given Zap
EOF

end
end


Phlip
http://flea.sourceforge.net/resume.html


#5

Aslak Hellesøy wrote:

f = p.parse_or_fail <<-EOF
Feature: Foo
Scenario: Bar
Given Zap
EOF

end
end

Please explain how it doesn’t work. Output, error etc.

Same as before:

$ ruby test/unit/cuke_test.rb
Loaded suite test/unit/cuke_test
Started
E
Finished in 0.127149 seconds.

  1. Error:
    test_parser(CukeFeatureParser):
    NameError: undefined local variable or method
    _nt_scenario_outline_keyword' for #<Cucumber::Parser::FeatureParser:0xb728ecc4> cucumber (0.3.0) lib/cucumber/parser/feature.rb:855:in_nt_scenario_outline’
    cucumber (0.3.0) lib/cucumber/parser/feature.rb:106:in
    _nt_feature' cucumber (0.3.0) lib/cucumber/parser/feature.rb:102:inloop’
    cucumber (0.3.0) lib/cucumber/parser/feature.rb:102:in
    _nt_feature' treetop (1.2.5) lib/treetop/runtime/compiled_parser.rb:18:insend’
    treetop (1.2.5) lib/treetop/runtime/compiled_parser.rb:18:in
    parse' cucumber (0.3.0) lib/cucumber/parser/treetop_ext.rb:79:inparse_or_fail’
    test/unit/cuke_test.rb:12:in `test_parser’

1 tests, 0 assertions, 0 failures, 1 errors


Phlip
http://flea.sourceforge.net/resume.html


#6

Den 25. april. 2009 kl. 13.10 skrev Phlip removed_email_address@domain.invalid:

Scenario: Bar
require File.dirname(FILE) + ‘/…/test_helper’
Feature: Foo
Scenario: Bar
Given Zap
EOF

end
end

Please explain how it doesn’t work. Output, error etc.

Aslak


#7

On Sat, Apr 25, 2009 at 5:00 PM, Phlip removed_email_address@domain.invalid wrote:

Cucumber.load_language(‘en’)

  1. Error:
    test_parser(CukeFeatureParser):
    NameError: undefined local variable or method `_nt_scenario_outline_keyword’

The #_nt_scenario_outline_keyword method comes from Ruby code that is
dynamically generated by Treetop while parsing the i18n.tt file. The
i18n.tt file parsed when you call Cucumber.load_parser (which
substitutes i18n keywords before passing it to Treetop). I’m not sure
what’s going on with your code.

It works for me - also in a Rails environment:
http://github.com/aslakhellesoy/cucumber_rails/commit/78b36a704279fab7e7ad47ccc3825916e5e9622c
What happens when you run the test I added here?

Aslak


#8

Bump?

Please explain how it doesn’t work. Output, error etc.

Same as before:

I also get it from a rspec-rails case…


#9

Bump?


#10

On Tue, Apr 28, 2009 at 8:56 AM, Phlip removed_email_address@domain.invalid wrote:

Bump?

Please explain how it doesn’t work. Output, error etc.

Same as before:

I also get it from a rspec-rails case…

Huh? What does this have to do w/ rspec-rails? This thread is about a
NameError on _nt_scenario_outline_keyword.


#11

Just one comment - I went down this path a bit, and ended up finding
it drastically easier to write a custom formatter.
Take a look at
http://wiki.github.com/aslakhellesoy/cucumber/custom-formatters

I’m sure there are places where you’d want to call the parser
directly; but everything I needed to do was handled more easily by
writing a formatter and catching the events I care about.

  • Korny

On Sat, Apr 25, 2009 at 2:07 PM, Phlip removed_email_address@domain.invalid wrote:

include Cucumber
NameError: undefined local variable or method `_nt_scenario_outline_keyword’
Phlip
http://flea.sourceforge.net/resume.html


rspec-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/rspec-users


Kornelis Sietsma korny at my surname dot com
“Every jumbled pile of person has a thinking part
that wonders what the part that isn’t thinking
isn’t thinking of”