/
saga_parser_spec.rb
135 lines (108 loc) · 3.85 KB
/
saga_parser_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require File.expand_path('../spec_helper', __FILE__)
module ParserHelper
def parser
@parser ||= Saga::Parser.new
end
def parse(input)
Saga::Parser.parse(input)
end
def parse_title
parser.parse("Requirements API\n\n")
end
def parse_introduction
parser.parse("This document describes our API.\n\n")
end
def parse_story_marker
parser.parse('USER STORIES')
end
def parse_header
parser.parse('Storage')
end
def parse_story
parser.parse('As a recorder I would like to add a recording so that it becomes available. - #1 todo')
end
def parse_story_comment
parser.parse(' “Your recording was created successfully.”')
end
def parse_definition
parser.parse('Other: Stories that don’t fit anywhere else.')
end
end
describe "Parser" do
it "should initialize and parse" do
document = Saga::Parser.parse('')
document.should.be.kind_of?(Saga::Document)
end
end
describe "A Parser, concerning the handling of input" do
extend ParserHelper
before { @parser = nil }
it "interprets the first line of the document as a title" do
document = parse('Requirements API')
document.title.should == 'API'
document = parse('Record and Search')
document.title.should == 'Record and Search'
end
it "interprets authors" do
document = parse('- Manfred Stienstra')
document.authors.map { |author| author[:name] }.should == ['Manfred Stienstra']
end
it "interprets the introduction" do
parse_title
parse_introduction
parser.document.introduction.should == ['This document describes our API.']
end
it "interprets stories without a header as being a gobal story" do
parse_title
parse_introduction
parse_story_marker
parse_story
parser.document.stories.keys.should == ['']
parser.document.stories[''].length.should == 1
parser.document.stories[''].first[:id].should == 1
end
it "interprets stories with a header as being part of that section" do
parse_title
parse_introduction
parse_story_marker
parse_header
parse_story
parser.document.stories.keys.should == ['Storage']
parser.document.stories['Storage'].length.should == 1
parser.document.stories['Storage'].first[:id].should == 1
end
it "interprets a comment after a story as being part of the story" do
parse_story_marker
parse_story
parse_story_comment
parser.document.stories.keys.should == ['']
parser.document.stories[''].length.should == 1
parser.document.stories[''].first[:id].should == 1
parser.document.stories[''].first[:notes].should == '“Your recording was created successfully.”'
end
it "interprets definitions without a header as being a gobal definition" do
parse_title
parse_introduction
parse_story_marker
parse_definition
parser.document.definitions.keys.should == ['']
parser.document.definitions[''].length.should == 1
parser.document.definitions[''].first[:title].should == 'Other'
end
it "interprets definitions with a header as being part of that section" do
parse_title
parse_introduction
parse_story_marker
parse_header
parse_definition
parser.document.definitions.keys.should == ['Storage']
parser.document.definitions['Storage'].length.should == 1
parser.document.definitions['Storage'].first[:title].should == 'Other'
end
it "properly parses hard cases" do
parse_story_marker
parser.parse('As a member I would like the app to keep the information it got from Twitter up-to-date so that changes I make on Twitter get propagated to my listing.')
story = parser.document.stories[''].first
story[:description].should == 'As a member I would like the app to keep the information it got from Twitter up-to-date so that changes I make on Twitter get propagated to my listing.'
end
end