Forum: RSpec [Cucumber] call the (Treetop?) parser directly?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-25 06:09
(Received via mailing list)
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:in `loop'
     ...

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

--
   Phlip
   http://flea.sourceforge.net/resume.html
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-25 10:44
(Received via mailing list)
On Sat, Apr 25, 2009 at 6:07 AM, Phlip <phlip2005@gmail.com> 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:in `loop'
>    ...
>
> 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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-25 13:05
(Received via mailing list)
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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-25 13:11
(Received via mailing list)
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
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-25 15:00
(Received via mailing list)
Den 25. april. 2009 kl. 13.10 skrev Phlip <phlip2005@gmail.com>:

>>>  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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-25 18:12
(Received via mailing list)
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: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
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-27 08:58
(Received via mailing list)
On Sat, Apr 25, 2009 at 5:00 PM, Phlip <phlip2005@gmail.com> 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/com...
What happens when you run the test I added here?

Aslak
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-28 15:58
(Received via mailing list)
Bump?

>> Please explain how it doesn't work. Output, error etc.
>
> Same as before:

I also get it from a rspec-rails case...
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-28 16:12
(Received via mailing list)
Bump?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-28 16:31
(Received via mailing list)
On Tue, Apr 28, 2009 at 8:56 AM, Phlip <phlip2005@gmail.com> 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.
D86508251e48b986057d34bf9ae3b6b3?d=identicon&s=25 Kornelis Sietsma (korny)
on 2009-04-29 13:35
(Received via mailing list)
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/cust...
- or see my post earlier at
http://groups.google.com/group/rspec/browse_thread...

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 <phlip2005@gmail.com> wrote:
>  include Cucumber
> NameError: undefined local variable or method `_nt_scenario_outline_keyword'
>  Phlip
>  http://flea.sourceforge.net/resume.html
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> 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"
This topic is locked and can not be replied to.