/
skin_test.rb
65 lines (51 loc) · 2.43 KB
/
skin_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
require "test_helper"
class SkinTest < MiniTest::Unit::TestCase
def test_template_can_be_loaded
skin = Slimmer::Skin.new asset_host: "http://example.local/"
expected_url = "http://example.local/templates/example.html.erb"
stub_request(:get, expected_url).to_return :body => "<foo />"
template = skin.template 'example'
assert_requested :get, "http://example.local/templates/example.html.erb"
assert_equal "<foo />", template
end
def test_templates_can_be_cached
skin = Slimmer::Skin.new asset_host: "http://example.local/", use_cache: true
expected_url = "http://example.local/templates/example.html.erb"
stub_request(:get, expected_url).to_return :body => "<foo />"
first_access = skin.template 'example'
second_access = skin.template 'example'
assert_requested :get, "http://example.local/templates/example.html.erb", times: 1
assert_same first_access, second_access
end
def test_should_interpolate_values_for_prefix
skin = Slimmer::Skin.new asset_host: "http://example.local/", use_cache: false, prefix: "this-is-the-prefix"
expected_url = "http://example.local/templates/example.html.erb"
stub_request(:get, expected_url).to_return :body => "<p><%= prefix %></p>"
template = skin.template 'example'
assert_equal "<p>this-is-the-prefix</p>", template
end
def test_should_raise_appropriate_exception_when_template_not_found
skin = Slimmer::Skin.new asset_host: "http://example.local/"
expected_url = "http://example.local/templates/example.html.erb"
stub_request(:get, expected_url).to_return(:status => '404')
assert_raises(Slimmer::TemplateNotFoundException) do
skin.template 'example'
end
end
def test_should_raise_appropriate_exception_when_cant_reach_template_host
skin = Slimmer::Skin.new asset_host: "http://example.local/"
expected_url = "http://example.local/templates/example.html.erb"
stub_request(:get, expected_url).to_raise(Errno::ECONNREFUSED)
assert_raises(Slimmer::CouldNotRetrieveTemplate) do
skin.template 'example'
end
end
def test_should_raise_appropriate_exception_when_hostname_cannot_be_resolved
skin = Slimmer::Skin.new asset_host: "http://non-existent.domain/"
expected_url = "http://non-existent.domain/templates/example.html.erb"
stub_request(:get, expected_url).to_raise(SocketError)
assert_raises(Slimmer::CouldNotRetrieveTemplate) do
skin.template 'example'
end
end
end