/
saga_tokenizer_spec.rb
117 lines (97 loc) · 3.55 KB
/
saga_tokenizer_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
require File.expand_path('../spec_helper', __FILE__)
module CasesHelper
def _parse_expected(line)
eval(line[3..-1])
end
def each_case(path)
filename = File.expand_path("../cases/#{path}.txt", __FILE__)
input = nil
File.readlines(filename).each do |line|
if input.nil?
input = line.strip
else
yield input, _parse_expected(line)
input = nil
end
end
end
end
describe "Tokenizer" do
extend CasesHelper
it "tokenizes story attributes input" do
each_case('story_attributes') do |input, expected|
Saga::Tokenizer.tokenize_story_attributes(input).should == expected
end
end
it "tokenizes story input" do
each_case('story') do |input, expected|
Saga::Tokenizer.tokenize_story(input).should == expected
end
end
it "tokenizes hard stories" do
Saga::Tokenizer.tokenize_story('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.').should == {
:description => '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
it "tokenizes definition input" do
each_case('definition') do |input, expected|
Saga::Tokenizer.tokenize_definition(input).should == expected
end
end
it "tokenizes author input" do
each_case('author') do |input, expected|
Saga::Tokenizer.tokenize_author(input).should == expected
end
end
end
describe "A Tokenizer" do
before do
@parser = stub('Parser')
@tokenizer = Saga::Tokenizer.new(@parser)
end
it "sends a tokenized story to the parser" do
line = 'As a recorder I would like to use TLS (SSL) so that my connection with the storage API is secure and I can be sure of the API’s identity. - #4 todo'
story = Saga::Tokenizer.tokenize_story(line)
@parser.expects(:handle_story).with(story)
@tokenizer.process_line(line)
end
it "sends a tokenized author to the parser" do
line = '- Manfred Stienstra, manfred@fngtps.com'
author = Saga::Tokenizer.tokenize_author(line)
@parser.expects(:handle_author).with(author)
@tokenizer.process_line(line)
end
it "sends a tokenized definition to the parser" do
line = 'Author: Someone who writes'
definition = Saga::Tokenizer.tokenize_definition(line)
@parser.expects(:handle_definition).with(definition)
@tokenizer.process_line(line)
end
it "doesn't mistake a story note with a semicolon as a definition" do
line = ' It would be nice if we could use http://www.braintreepaymentsolutions.com/'
@parser.expects(:handle_string).with(line)
@tokenizer.process_line(line)
end
it "send a tokenize defintion to the parser (slighly more complex)" do
line = 'Search and retrieval: Stories related to selecting and retrieving recordings.'
definition = Saga::Tokenizer.tokenize_definition(line)
@parser.expects(:handle_definition).with(definition)
@tokenizer.process_line(line)
end
it "forwards plain strings to the parser" do
[
'Requirements User Application',
'USER STORIES',
''
].each do |line|
@parser.expects(:handle_string).with(line)
@tokenizer.process_line(line)
end
end
it "processes lines from the input" do
input = File.read(File.expand_path("../cases/story.txt", __FILE__))
count = input.split("\n").length
@tokenizer.expects(:process_line).times(count)
@tokenizer.process(input)
end
end