[rspec-users] [Cucumber] call the (Treetop?) parser directly?

aslak hellesoy aslak.hellesoy at gmail.com
Sun Apr 26 11:04:54 EDT 2009


On Sat, Apr 25, 2009 at 5:00 PM, Phlip <phlip2005 at gmail.com> wrote:
> Aslak Hellesøy wrote:
>
>>> 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
>>>
>>
>> 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'

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

> 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:in `loop'
>    cucumber (0.3.0) lib/cucumber/parser/feature.rb:102:in `_nt_feature'
>    treetop (1.2.5) lib/treetop/runtime/compiled_parser.rb:18:in `send'
>    treetop (1.2.5) lib/treetop/runtime/compiled_parser.rb:18:in `parse'
>    cucumber (0.3.0) lib/cucumber/parser/treetop_ext.rb:79:in `parse_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
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list