Skip to content

Instantly share code, notes, and snippets.

@msassak
Created December 14, 2009 22:25
Show Gist options
  • Select an option

  • Save msassak/256495 to your computer and use it in GitHub Desktop.

Select an option

Save msassak/256495 to your computer and use it in GitHub Desktop.
Given a feature like so:
@wip
Feature: My Feature
@explode
Scenario: A scenario
Given foo
When bar
Then baz
Scenario Outline: A bunch of scenarios
Given <something>
When I <action>
Then I should see <some text>
Examples:
| something | action | some text |
| foo | kick | ouch! |
| bar | punch | win! |
When it's parsed, I imagine being able to do this:
ast.root.name # => "My Feature"
ast.scenarios.first.root #=> <Feature object>
ast.scenarios.first.feature # alias for #root
ast.all_scenarios # => [<scenario: "A scenario">, <scenario: "foo / kick / ouch!">,
# <scenario: "bar / punch / win!">]
ast.scenario_outlines.first.examples.first.scenarios # => [<scenario: "foo / kick / ouch!">,
# <scenario: "bar / punch / win!">]
# (Not that you would *want* to do this)
ast.children # => [<tag :wip>, <scenario "A scenario">...]
ast.descendants # => [<tag :wip>, <tag :explode>, <scenario "A scenario">, <Step "Given foo">...]
ast.scenarios.first.children # => [<tag :explode>, <step "Given foo">...]
That's what I imagine at least. #each / enumeration is more interesting. In my mind this is the most
important part to get right, just thinking about being able to call ast.partition and ast.inject makes me
a happy boy. The question about #each is, do you return all the concrete elements (tags, comments, etc.),
or does each yield the results of #all_scenarios?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment