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

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/story/runner/story_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ State

Returns a new instance of State.



97
98
99
# File 'lib/spec/story/runner/story_parser.rb', line 97

def initialize(parser)
  @parser = parser
end

Instance Method Details

#comment(line) ⇒ Object



145
146
# File 'lib/spec/story/runner/story_parser.rb', line 145

def comment(line)
end

#eofObject



138
139
# File 'lib/spec/story/runner/story_parser.rb', line 138

def eof
end

#event(line) ⇒ Object



121
122
123
124
# File 'lib/spec/story/runner/story_parser.rb', line 121

def event(line)
  @parser.create_when(remove_tag_from(:when, line))
  @parser.transition_to(:when_state)
end

#given(line) ⇒ Object



111
112
113
114
# File 'lib/spec/story/runner/story_parser.rb', line 111

def given(line)
  @parser.create_given(remove_tag_from(:given, line))
  @parser.transition_to(:given_state)
end

#given_scenario(line) ⇒ Object



116
117
118
119
# File 'lib/spec/story/runner/story_parser.rb', line 116

def given_scenario(line)
  @parser.create_given_scenario(remove_tag_from(:givenscenario, line))
  @parser.transition_to(:given_state)
end

#other(line) ⇒ Object



141
142
143
# File 'lib/spec/story/runner/story_parser.rb', line 141

def other(line)
  # no-op - supports header text before the first story in a file
end

#outcome(line) ⇒ Object



126
127
128
129
# File 'lib/spec/story/runner/story_parser.rb', line 126

def outcome(line)
  @parser.create_then(remove_tag_from(:then, line))
  @parser.transition_to(:then_state)
end

#remove_tag_from(tag, line) ⇒ Object



131
132
133
134
135
136
# File 'lib/spec/story/runner/story_parser.rb', line 131

def remove_tag_from(tag, line)
  tokens = line.split
  # validation of tag can go here
  tokens[0].downcase.match(/#{tag.to_s}:?/) ? 
                      (tokens[1..-1].join(' ')) : line
end

#scenario(line) ⇒ Object



106
107
108
109
# File 'lib/spec/story/runner/story_parser.rb', line 106

def scenario(line)
  @parser.create_scenario(line)
  @parser.transition_to(:scenario_state)
end

#story(line) ⇒ Object



101
102
103
104
# File 'lib/spec/story/runner/story_parser.rb', line 101

def story(line)
  @parser.init_story(line)
  @parser.transition_to(:story_state)
end