-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrack_spec.rb
65 lines (51 loc) · 1.29 KB
/
rack_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
require './pronounce'
require './suggest'
require 'rack/test'
require 'rspec'
describe 'the app' do
include Rack::Test::Methods
def app
Rack::Builder.new do
words = Trie.new.insert('a', 'AH0')
for i in 0..9
words.insert("a(2)#{i}", 'smt')
end
map '/pronounce' do
run Pronounce.new(words)
end
map '/suggest' do
run Suggest.new(words)
end
end.to_app
end
context '/pronounce' do
before do
get '/pronounce'
end
it 'returns the status 200' do
expect(last_response.status).to eq 200
end
it 'returns json' do
expect(last_response.header).to include('Content-Type' => 'application/json')
end
it 'returns pronunciation' do
get '/pronounce/a'
expect(last_response.body).to include('AH0')
end
end
context '/suggest' do
before do
get '/suggest'
end
it 'returns the status 200' do
expect(last_response.status).to eq 200
end
it 'returns json' do
expect(last_response.header).to include('Content-Type' => 'application/json')
end
it 'returns 10 words' do
get '/suggest/a'
expect(last_response.body).to include('a', 'a(2)0', 'a(2)1', 'a(2)2', 'a(2)3', 'a(2)4', 'a(2)5', 'a(2)6', 'a(2)7', 'a(2)8')
end
end
end