| Class | Spec::Story::Runner::StoryParser |
| In: |
lib/spec/story/runner/story_parser.rb
|
| Parent: | Object |
# 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
# File lib/spec/story/runner/story_parser.rb, line 45
45: def add_story_line(line)
46: @current_story_lines << line
47: end
# File lib/spec/story/runner/story_parser.rb, line 60
60: def create_given(name)
61: @story_mediator.create_given(name)
62: end
# 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
# 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
# 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
# File lib/spec/story/runner/story_parser.rb, line 72
72: def create_then(name)
73: @story_mediator.create_then(name)
74: end
# File lib/spec/story/runner/story_parser.rb, line 68
68: def create_when(name)
69: @story_mediator.create_when(name)
70: end
# 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
# 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
# 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
# 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