/
test.rb
68 lines (62 loc) · 1.61 KB
/
test.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
ENV['RACK_ENV'] = 'test'
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'rack/test'
require 'lib/barcode_service'
class BarcodeServiceTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
context "on GET to /" do
setup {
get '/'
}
should "return ok" do
assert last_response.ok?
end
should "have some kind of welcome" do
assert last_response.body =~ /<img/
end
end
{:eps => /%!PS-Adobe-2.0 EPSF-1.2/,
:gif => /^GIF89/,
:png => /^.?PNG/,
:jpeg => //
}.each do |format, fileheader|
context "on GET with code and #{format} type" do
setup {
get "/1234322.#{format}"
}
should "return ok" do
assert last_response.ok?
end
should "cache for a year" do
assert_equal 'public, max-age=31536000',
last_response.headers['Cache-Control']
end
should "return #{format} content-type" do
assert_equal "image/#{format}", last_response.headers['Content-Type']
end
should "return the #{format} document" do
body = last_response.body
body.force_encoding('binary') if body.respond_to?(:force_encoding)
assert body =~ fileheader
end
end
end
TYPES.each do |type,_|
context "on GET with code and #{type} barcode" do
setup {
get "/1234322.png?type=#{type}"
}
should "return ok" do
assert last_response.ok?
end
should "return png content-type" do
assert_equal "image/png", last_response.headers['Content-Type']
end
end
end
end