guard-bosh 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/guard/bosh/template_renderer.rb +21 -5
- data/spec/guard/bosh/template_renderer_spec.rb +52 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ca6f0f55880bc7db9d36d693036a5626b228a0
|
4
|
+
data.tar.gz: 269d78e98809510e93ae63d48da0809f8e567270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a0ba80730401e7a0f7ec1d13c0fba3464fdea1c5c96f6f839bcbfa4f179103271a658bbb8d8f96c9f25b9fa2ced000d4ab50534ca0e72e54d555776f8c0cd5d
|
7
|
+
data.tar.gz: 96ab6eec2791ca84dc582eae3dece52d7a749f835f4646a3f7c3904cee6f2fed76f6a2c6bc0cec06eeade259af44814cd873a8030efcb7f8a887e26d5bb6412f
|
@@ -8,17 +8,33 @@ module Guard
|
|
8
8
|
def render(context:, template:)
|
9
9
|
renderer = ::Bosh::Template::Renderer.new(
|
10
10
|
context: JSON.generate(context))
|
11
|
+
|
12
|
+
# The re-writing of messages we do here is intended to make the output
|
13
|
+
# more readable, but may not be wise.
|
11
14
|
begin
|
12
15
|
renderer.render(template)
|
13
16
|
{ template: template, status: :success, detail: '' }
|
14
17
|
rescue ::Bosh::Template::UnknownProperty => e
|
15
|
-
{
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
error(template, "missing property: #{e.name}")
|
19
|
+
rescue NoMethodError => e
|
20
|
+
error(template, e.message.sub(/ for #<[^>]+>$/, ''))
|
21
|
+
rescue NameError => e
|
22
|
+
error(template, e.message.sub(/ for #<[^>]+>$/, ''))
|
23
|
+
rescue SyntaxError => e
|
24
|
+
error(template, e.message.split("\n").first.sub(
|
25
|
+
/^\(erb\):[0-9]+: /, ''))
|
20
26
|
end
|
21
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def error(template, message)
|
32
|
+
{
|
33
|
+
template: template,
|
34
|
+
status: :failure,
|
35
|
+
detail: message
|
36
|
+
}
|
37
|
+
end
|
22
38
|
end
|
23
39
|
end
|
24
40
|
end
|
@@ -7,10 +7,14 @@ describe Guard::Bosh::TemplateRenderer do
|
|
7
7
|
Guard::Bosh::TemplateRenderer.new
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:bosh_renderer) { instance_double(::Bosh::Template::Renderer) }
|
11
|
+
before do
|
12
|
+
expect(::Bosh::Template::Renderer).to receive(:new).with(
|
13
|
+
context: '{}').and_return(bosh_renderer)
|
14
|
+
end
|
15
|
+
|
10
16
|
context 'when the template contains no errors' do
|
11
17
|
it 'reports that no error occurred' do
|
12
|
-
bosh_renderer = instance_double(::Bosh::Template::Renderer)
|
13
|
-
expect(::Bosh::Template::Renderer).to receive(:new).with(context: '{}').and_return(bosh_renderer)
|
14
18
|
expect(bosh_renderer).to receive(:render).with('config.erb')
|
15
19
|
result = subject.render(context: {}, template: 'config.erb')
|
16
20
|
expect(result).to eq(template: 'config.erb', status: :success, detail: '')
|
@@ -19,11 +23,53 @@ describe Guard::Bosh::TemplateRenderer do
|
|
19
23
|
|
20
24
|
context 'when the template refers to an unknown property' do
|
21
25
|
it 'reports the missing property' do
|
22
|
-
bosh_renderer
|
23
|
-
|
24
|
-
|
26
|
+
expect(bosh_renderer).to receive(:render).with('config.erb').and_raise(
|
27
|
+
::Bosh::Template::UnknownProperty.new('redis.port'))
|
28
|
+
result = subject.render(context: {}, template: 'config.erb')
|
29
|
+
expect(result).to eq(
|
30
|
+
template: 'config.erb',
|
31
|
+
status: :failure,
|
32
|
+
detail: 'missing property: redis.port'
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when the template calls a misnamed helper method' do
|
38
|
+
it 'reports the missing helper method' do
|
39
|
+
expect(bosh_renderer).to receive(:render).with('config.erb').and_raise(
|
40
|
+
NoMethodError.new("undefined method `o' for #<Bosh::Template::EvaluationContext:0x00000000000000>"))
|
41
|
+
result = subject.render(context: {}, template: 'config.erb')
|
42
|
+
expect(result).to eq(
|
43
|
+
template: 'config.erb',
|
44
|
+
status: :failure,
|
45
|
+
detail: "undefined method `o'"
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when the template references a missing name' do
|
51
|
+
it 'reports the missing name' do
|
52
|
+
expect(bosh_renderer).to receive(:render).with('config.erb').and_raise(
|
53
|
+
NameError.new("undefined local variable or method `missing' for #<Bosh::Template::EvaluationContext:0x00000000000000>"))
|
54
|
+
result = subject.render(context: {}, template: 'config.erb')
|
55
|
+
expect(result).to eq(
|
56
|
+
template: 'config.erb',
|
57
|
+
status: :failure,
|
58
|
+
detail: "undefined local variable or method `missing'"
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the template is not well-formed' do
|
64
|
+
it 'reports the template error' do
|
65
|
+
expect(bosh_renderer).to receive(:render).with('config.erb').and_raise(
|
66
|
+
SyntaxError.new("(erb):7: syntax error, unexpected end-of-input, expecting keyword_end\n; _erbout.force_encoding(__ENCODING__)"))
|
25
67
|
result = subject.render(context: {}, template: 'config.erb')
|
26
|
-
expect(result).to eq(
|
68
|
+
expect(result).to eq(
|
69
|
+
template: 'config.erb',
|
70
|
+
status: :failure,
|
71
|
+
detail: 'syntax error, unexpected end-of-input, expecting keyword_end'
|
72
|
+
)
|
27
73
|
end
|
28
74
|
end
|
29
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-bosh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Crump
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bosh-template
|