Class: Spec::Story::Runner::StoryParser

Class | Spec::Story::Runner::StoryParser
In: | lib/spec/story/runner/story_parser.rb
Parent: | Object

### Methods

add_story_line create_given create_given_scenario create_scenario create_story create_then create_when init_story new parse process_line states transition_to

### Classes and Modules

Class Spec::Story::Runner::StoryParser::GivenState
Class Spec::Story::Runner::StoryParser::ScenarioState
Class Spec::Story::Runner::StoryParser::StartingState
Class Spec::Story::Runner::StoryParser::State
Class Spec::Story::Runner::StoryParser::StoryState
Class Spec::Story::Runner::StoryParser::ThenState
Class Spec::Story::Runner::StoryParser::WhenState

### Public Class methods

new(story_mediator)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 12
    12:         def initialize(story_mediator)
    13:           @story_mediator = story_mediator
    14:           @current_story_lines = []
    15:           transition_to(:starting_state)
    16:         end

### Public Instance methods

add_story_line(line)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 45
    45:         def add_story_line(line)
    46:           @current_story_lines << line
    47:         end

create_given(name)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 60
    60:         def create_given(name)
    61:           @story_mediator.create_given(name)
    62:         end

create_given_scenario(name)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 64
    64:         def create_given_scenario(name)
    65:           @story_mediator.create_given_scenario(name)
    66:         end

create_scenario(title)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 56
    56:         def create_scenario(title)
    57:           @story_mediator.create_scenario(title.gsub("Scenario: ",""))
    58:         end

create_story()

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 49
    49:         def create_story()
    50:           unless @current_story_lines.empty?
    51:             @story_mediator.create_story(@current_story_lines[0].gsub("Story: ",""), @current_story_lines[1..-1].join("\n"))
    52:             @current_story_lines.clear
    53:           end
    54:         end

create_then(name)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 72
    72:         def create_then(name)
    73:           @story_mediator.create_then(name)
    74:         end

create_when(name)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 68
    68:         def create_when(name)
    69:           @story_mediator.create_when(name)
    70:         end

init_story(title)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 40
    40:         def init_story(title)
    41:           @current_story_lines.clear
    42:           add_story_line(title)
    43:         end

parse(lines)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 18
    18:         def parse(lines)
    19:           lines.reject! {|line| line == ""}
    20:           until lines.empty?
    21:             process_line(lines.shift)
    22:           end
    23:           @state.eof
    24:         end

process_line(line)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 26
    26:         def process_line(line)
    27:           line.strip!
    28:           case line
    29:           when /^Story: /           then @state.story(line)
    30:           when /^Scenario: /        then @state.scenario(line)
    31:           when /^Given:? /          then @state.given(line)
    32:           when /^GivenScenario:? /  then @state.given_scenario(line)
    33:           when /^When:? /           then @state.event(line)
    34:           when /^Then:? /           then @state.outcome(line)
    35:           when /^And:? /            then @state.one_more_of_the_same(line)
    36:           else                           @state.other(line)
    37:           end
    38:         end

states()

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 80
    80:         def states
    81:           @states ||= {
    82:             :starting_state => StartingState.new(self),
    83:             :story_state => StoryState.new(self),
    84:             :scenario_state => ScenarioState.new(self),
    85:             :given_state => GivenState.new(self),
    86:             :when_state => WhenState.new(self),
    87:             :then_state => ThenState.new(self)
    88:           }
    89:         end

transition_to(key)

[Source]

        # File lib/spec/story/runner/story_parser.rb, line 76
    76:         def transition_to(key)
    77:           @state = states[key]
    78:         end

[Validate]