23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/isomorfeus_operation/lucid_operation/gherkin.rb', line 23
def self.parse(gherkin_text)
operation = { operation: '', procedure: '', steps: [], failure: [], ensure: [] }
has_finally = false
lines = gherkin_text.split(NEWLINE)
lines.each do |line|
case line
when STAR, GIVEN, WHEN, THEN, AND
Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
operation[:steps] << $1.strip
when ENSURE
operation[:ensure] << $1.strip
when IW_FAILING, IF_ITT_FAILED, FAILED
operation[:failure] << $1.strip
when FIRST
Isomorfeus.raise_error(message: FIRST_EXCEPTION) if operation[:steps].size > 0
operation[:steps] << $1.strip
when FINALLY
Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
operation[:steps] << $1.strip
has_finally = true
when PROCEDURE
Isomorfeus.raise_error(message: 'No Operation defined!') if operation[:operation].empty?
Isomorfeus.raise_error(message: 'Procedure already defined!') unless operation[:procedure].empty?
operation[:procedure] = $1.strip
when OPERATION
Isomorfeus.raise_error(message: 'Operation already defined!') unless operation[:operation].empty?
operation[:operation] = $1.strip
when WHITE_SPACE, COMMENT
else
Isomorfeus.raise_error(message: "Unknown key word(s) at the beginning of the line: #{line}") unless operation[:procedure].empty?
operation[:description] = [] unless operation.key?(:description)
operation[:description] << line.strip
end
end
operation
end
|