inversion 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -0
- data/.gemtest +0 -0
- data/ChangeLog +836 -0
- data/History.md +4 -0
- data/Manifest.txt +74 -0
- data/README.rdoc +171 -0
- data/Rakefile +55 -0
- data/bin/inversion +276 -0
- data/lib/inversion.rb +98 -0
- data/lib/inversion/exceptions.rb +21 -0
- data/lib/inversion/mixins.rb +236 -0
- data/lib/inversion/monkeypatches.rb +20 -0
- data/lib/inversion/renderstate.rb +337 -0
- data/lib/inversion/sinatra.rb +35 -0
- data/lib/inversion/template.rb +250 -0
- data/lib/inversion/template/attrtag.rb +120 -0
- data/lib/inversion/template/calltag.rb +16 -0
- data/lib/inversion/template/codetag.rb +164 -0
- data/lib/inversion/template/commenttag.rb +54 -0
- data/lib/inversion/template/conditionaltag.rb +49 -0
- data/lib/inversion/template/configtag.rb +60 -0
- data/lib/inversion/template/containertag.rb +45 -0
- data/lib/inversion/template/elsetag.rb +62 -0
- data/lib/inversion/template/elsiftag.rb +49 -0
- data/lib/inversion/template/endtag.rb +55 -0
- data/lib/inversion/template/escapetag.rb +26 -0
- data/lib/inversion/template/fortag.rb +120 -0
- data/lib/inversion/template/iftag.rb +69 -0
- data/lib/inversion/template/importtag.rb +70 -0
- data/lib/inversion/template/includetag.rb +51 -0
- data/lib/inversion/template/node.rb +102 -0
- data/lib/inversion/template/parser.rb +297 -0
- data/lib/inversion/template/pptag.rb +28 -0
- data/lib/inversion/template/publishtag.rb +72 -0
- data/lib/inversion/template/subscribetag.rb +88 -0
- data/lib/inversion/template/tag.rb +150 -0
- data/lib/inversion/template/textnode.rb +43 -0
- data/lib/inversion/template/unlesstag.rb +60 -0
- data/lib/inversion/template/uriencodetag.rb +30 -0
- data/lib/inversion/template/yieldtag.rb +51 -0
- data/lib/inversion/tilt.rb +82 -0
- data/lib/inversion/utils.rb +235 -0
- data/spec/data/sinatra/hello.inversion +1 -0
- data/spec/inversion/mixins_spec.rb +177 -0
- data/spec/inversion/monkeypatches_spec.rb +35 -0
- data/spec/inversion/renderstate_spec.rb +291 -0
- data/spec/inversion/sinatra_spec.rb +59 -0
- data/spec/inversion/template/attrtag_spec.rb +216 -0
- data/spec/inversion/template/calltag_spec.rb +30 -0
- data/spec/inversion/template/codetag_spec.rb +51 -0
- data/spec/inversion/template/commenttag_spec.rb +84 -0
- data/spec/inversion/template/configtag_spec.rb +105 -0
- data/spec/inversion/template/containertag_spec.rb +54 -0
- data/spec/inversion/template/elsetag_spec.rb +105 -0
- data/spec/inversion/template/elsiftag_spec.rb +87 -0
- data/spec/inversion/template/endtag_spec.rb +78 -0
- data/spec/inversion/template/escapetag_spec.rb +59 -0
- data/spec/inversion/template/fortag_spec.rb +98 -0
- data/spec/inversion/template/iftag_spec.rb +241 -0
- data/spec/inversion/template/importtag_spec.rb +106 -0
- data/spec/inversion/template/includetag_spec.rb +108 -0
- data/spec/inversion/template/node_spec.rb +81 -0
- data/spec/inversion/template/parser_spec.rb +170 -0
- data/spec/inversion/template/pptag_spec.rb +51 -0
- data/spec/inversion/template/publishtag_spec.rb +69 -0
- data/spec/inversion/template/subscribetag_spec.rb +60 -0
- data/spec/inversion/template/tag_spec.rb +97 -0
- data/spec/inversion/template/textnode_spec.rb +86 -0
- data/spec/inversion/template/unlesstag_spec.rb +84 -0
- data/spec/inversion/template/uriencodetag_spec.rb +49 -0
- data/spec/inversion/template/yieldtag_spec.rb +54 -0
- data/spec/inversion/template_spec.rb +269 -0
- data/spec/inversion/tilt_spec.rb +47 -0
- data/spec/inversion_spec.rb +95 -0
- data/spec/lib/constants.rb +9 -0
- data/spec/lib/helpers.rb +160 -0
- metadata +316 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env rspec -cfd -b
|
2
|
+
# vim: set noet nosta sw=4 ts=4 :
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
require 'inversion/template/uriencodetag'
|
16
|
+
|
17
|
+
describe Inversion::Template::UriencodeTag do
|
18
|
+
|
19
|
+
before( :all ) do
|
20
|
+
setup_logging( :fatal )
|
21
|
+
end
|
22
|
+
|
23
|
+
after( :all ) do
|
24
|
+
reset_logging()
|
25
|
+
end
|
26
|
+
|
27
|
+
before( :each ) do
|
28
|
+
@attribute_object = mock( "template attribute" )
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it "URI encodes the results of rendering" do
|
33
|
+
template = Inversion::Template.new( 'this is<?uriencode foo.bar ?>' )
|
34
|
+
template.foo = @attribute_object
|
35
|
+
@attribute_object.should_receive( :bar ).with( no_args() ).
|
36
|
+
and_return( " 25% Sparta!" )
|
37
|
+
|
38
|
+
template.render.should == "this is%2025%25%20Sparta%21"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "stringifies its content before encoding" do
|
42
|
+
template = Inversion::Template.new( '<?uriencode foo.bar ?> bottles of beer on the wall' )
|
43
|
+
template.foo = @attribute_object
|
44
|
+
@attribute_object.should_receive( :bar ).with( no_args() ).
|
45
|
+
and_return( 99.999 )
|
46
|
+
|
47
|
+
template.render.should == "99.999 bottles of beer on the wall"
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env rspec -cfd -b
|
2
|
+
# vim: set noet nosta sw=4 ts=4 :
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
require 'inversion/template/yieldtag'
|
16
|
+
|
17
|
+
describe Inversion::Template::YieldTag do
|
18
|
+
|
19
|
+
before( :all ) do
|
20
|
+
setup_logging( :fatal )
|
21
|
+
end
|
22
|
+
|
23
|
+
after( :all ) do
|
24
|
+
reset_logging()
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
it "calls the renderstate's block before rendering, and renders as its return value" do
|
29
|
+
tag = Inversion::Template::YieldTag.new
|
30
|
+
renderstate = Inversion::RenderState.new do |state|
|
31
|
+
:return_value
|
32
|
+
end
|
33
|
+
tag.before_rendering( renderstate )
|
34
|
+
|
35
|
+
rendered_output = renderstate.with_destination( [] ) do
|
36
|
+
renderstate << tag
|
37
|
+
end
|
38
|
+
|
39
|
+
rendered_output.should == [ :return_value ]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "renders as nothing if there wasn't a render block" do
|
43
|
+
tag = Inversion::Template::YieldTag.new
|
44
|
+
renderstate = Inversion::RenderState.new
|
45
|
+
tag.before_rendering( renderstate )
|
46
|
+
|
47
|
+
rendered_output = renderstate.with_destination( [] ) do
|
48
|
+
renderstate << tag
|
49
|
+
end
|
50
|
+
|
51
|
+
rendered_output.should == [ nil ]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
#!/usr/bin/env rspec -cfd -b
|
2
|
+
# vim: set noet nosta sw=4 ts=4 :
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname( __FILE__ ).dirname.parent.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'stringio'
|
15
|
+
|
16
|
+
require 'spec/lib/helpers'
|
17
|
+
require 'inversion/template'
|
18
|
+
|
19
|
+
describe Inversion::Template do
|
20
|
+
|
21
|
+
before( :all ) do
|
22
|
+
setup_logging( :fatal )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can be loaded from a String" do
|
26
|
+
Inversion::Template.new( "a template" ).source.should == 'a template'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "renders the source as-is if there are no instructions" do
|
30
|
+
Inversion::Template.new( "a template" ).render.should == 'a template'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "renders when stringified" do
|
34
|
+
Inversion::Template.new( "a template" ).to_s.should == 'a template'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "untaints template content loaded from a file" do
|
38
|
+
content = 'file contents'.taint
|
39
|
+
IO.should_receive( :read ).with( '/tmp/hooowat' ).and_return( content )
|
40
|
+
|
41
|
+
Inversion::Template.load( '/tmp/hooowat' ).source.should_not be_tainted()
|
42
|
+
end
|
43
|
+
|
44
|
+
it "calls before and after rendering hooks on all of its nodes when rendered" do
|
45
|
+
node = double( "fake node" )
|
46
|
+
parentstate = Inversion::RenderState.new( :foo => 'the merged stuff' )
|
47
|
+
tmpl = Inversion::Template.new( '' )
|
48
|
+
tmpl.node_tree << node
|
49
|
+
|
50
|
+
node.should_receive( :before_rendering ).with( an_instance_of(Inversion::RenderState) )
|
51
|
+
node.should_receive( :render ).with( an_instance_of(Inversion::RenderState) )
|
52
|
+
node.should_receive( :after_rendering ).with( an_instance_of(Inversion::RenderState) )
|
53
|
+
|
54
|
+
tmpl.render( parentstate )
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it "passes the block it was rendered with to its RenderState" do
|
59
|
+
node = double( "fake node", :before_rendering => nil, :after_rendering => nil )
|
60
|
+
tmpl = Inversion::Template.new( '' )
|
61
|
+
tmpl.node_tree << node
|
62
|
+
|
63
|
+
renderblock = Proc.new {}
|
64
|
+
node.should_receive( :render ).and_return do |renderstate|
|
65
|
+
renderstate.block.should equal( renderblock )
|
66
|
+
end
|
67
|
+
|
68
|
+
tmpl.render( &renderblock )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "can make an human-readable string version of itself suitable for debugging" do
|
72
|
+
IO.should_receive( :read ).with( '/tmp/inspect.tmpl' ).and_return( '<?attr foo ?>' )
|
73
|
+
tmpl = Inversion::Template.load( '/tmp/inspect.tmpl' )
|
74
|
+
tmpl.inspect.should =~ /Inversion::Template/
|
75
|
+
tmpl.inspect.should =~ %r{/tmp/inspect.tmpl}
|
76
|
+
tmpl.inspect.should =~ /attributes/
|
77
|
+
tmpl.inspect.should =~ /node_tree/
|
78
|
+
end
|
79
|
+
|
80
|
+
it "provides accessors for attributes that aren't identifiers in the template" do
|
81
|
+
tmpl = Inversion::Template.new( '' )
|
82
|
+
tmpl.foo = :bar
|
83
|
+
tmpl.foo.should == :bar
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
context "without template paths set" do
|
88
|
+
|
89
|
+
before( :each ) do
|
90
|
+
Inversion::Template.config[:template_paths].clear
|
91
|
+
end
|
92
|
+
|
93
|
+
it "instances can be loaded from an absolute path" do
|
94
|
+
IO.should_receive( :read ).with( '/tmp/hooowat' ).and_return( 'file contents' )
|
95
|
+
Inversion::Template.load( '/tmp/hooowat' ).source.should == 'file contents'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "instances can be loaded from a path relative to the current working directory" do
|
99
|
+
tmplpath = Pathname.pwd + 'hooowat.tmpl'
|
100
|
+
FileTest.should_receive( :exist? ).with( tmplpath.to_s ).and_return( true )
|
101
|
+
IO.should_receive( :read ).with( tmplpath.to_s ).and_return( 'file contents' )
|
102
|
+
Inversion::Template.load( 'hooowat.tmpl' ).source.should == 'file contents'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
context "with template paths set" do
|
108
|
+
|
109
|
+
before( :each ) do
|
110
|
+
Inversion::Template.config[:template_paths] = [ '/tmp', '/fun' ]
|
111
|
+
end
|
112
|
+
|
113
|
+
after( :each ) do
|
114
|
+
Inversion::Template.config[:template_paths].clear
|
115
|
+
end
|
116
|
+
|
117
|
+
it "instances can be loaded from an absolute path" do
|
118
|
+
FileTest.should_not_receive( :exist? )
|
119
|
+
|
120
|
+
IO.should_receive( :read ).with( '/tmp/hooowat' ).and_return( 'file contents' )
|
121
|
+
Inversion::Template.load( '/tmp/hooowat' ).source.should == 'file contents'
|
122
|
+
end
|
123
|
+
|
124
|
+
it "raises a runtime exception if unable to locate the template" do
|
125
|
+
tmplpath = Pathname.pwd + 'sadmanhose.tmpl'
|
126
|
+
|
127
|
+
FileTest.should_receive( :exist? ).with( '/tmp/sadmanhose.tmpl' ).and_return( false )
|
128
|
+
FileTest.should_receive( :exist? ).with( '/fun/sadmanhose.tmpl' ).and_return( false )
|
129
|
+
FileTest.should_receive( :exist? ).with( tmplpath.to_s ).and_return( false )
|
130
|
+
|
131
|
+
expect {
|
132
|
+
Inversion::Template.load( 'sadmanhose.tmpl' )
|
133
|
+
}.to raise_error( RuntimeError, /unable to find template ".+" within configured paths/i )
|
134
|
+
end
|
135
|
+
|
136
|
+
it "loads template relative to directories in the template_paths" do
|
137
|
+
FileTest.should_receive( :exist? ).with( '/tmp/hooowat.tmpl' ).and_return( false )
|
138
|
+
FileTest.should_receive( :exist? ).with( '/fun/hooowat.tmpl' ).and_return( true )
|
139
|
+
IO.should_receive( :read ).with( '/fun/hooowat.tmpl' ).and_return( 'file contents' )
|
140
|
+
|
141
|
+
Inversion::Template.load( 'hooowat.tmpl' ).source.should == 'file contents'
|
142
|
+
end
|
143
|
+
|
144
|
+
it "falls back to loading the template relative to the current working directory" do
|
145
|
+
tmplpath = Pathname.pwd + 'hooowat.tmpl'
|
146
|
+
|
147
|
+
FileTest.should_receive( :exist? ).with( '/tmp/hooowat.tmpl' ).and_return( false )
|
148
|
+
FileTest.should_receive( :exist? ).with( '/fun/hooowat.tmpl' ).and_return( false )
|
149
|
+
FileTest.should_receive( :exist? ).with( tmplpath.to_s ).and_return( true )
|
150
|
+
IO.should_receive( :read ).with( tmplpath.to_s ).and_return( 'file contents' )
|
151
|
+
|
152
|
+
Inversion::Template.load( 'hooowat.tmpl' ).source.should == 'file contents'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
context "with an attribute PI" do
|
158
|
+
|
159
|
+
let( :template ) { Inversion::Template.new("<h1><?attr foo ?></h1>") }
|
160
|
+
|
161
|
+
|
162
|
+
it "has a reader for getting the attribute's value" do
|
163
|
+
template.should respond_to( :foo )
|
164
|
+
end
|
165
|
+
|
166
|
+
it "has an accessor for setting the attribute's value" do
|
167
|
+
template.should respond_to( :foo= )
|
168
|
+
end
|
169
|
+
|
170
|
+
it "renders scalar values set for the attribute" do
|
171
|
+
template.foo = "a lion"
|
172
|
+
template.render.should == "<h1>a lion</h1>"
|
173
|
+
end
|
174
|
+
|
175
|
+
it "renders an non-String value set for the attribute using #to_s" do
|
176
|
+
template.foo = [ 'a lion', 'a little guy', 'a bad mousie', 'one birdy' ]
|
177
|
+
template.render.should == %{<h1>a liona little guya bad mousieone birdy</h1>}
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
context "with several attribute PIs" do
|
183
|
+
|
184
|
+
let( :template ) { Inversion::Template.new("<h1><?attr foo ?> <?attr foo?> RUN!</h1>") }
|
185
|
+
|
186
|
+
it "has a reader for getting the attribute's value" do
|
187
|
+
template.should respond_to( :foo )
|
188
|
+
end
|
189
|
+
|
190
|
+
it "has an accessor for setting the attribute's value" do
|
191
|
+
template.should respond_to( :foo= )
|
192
|
+
end
|
193
|
+
|
194
|
+
it "renders scalar values set for the attribute(s)" do
|
195
|
+
template.foo = "lions!!"
|
196
|
+
template.render.should == "<h1>lions!! lions!! RUN!</h1>"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
describe "Configurability support", :if => defined?( Configurability ) do
|
202
|
+
|
203
|
+
after( :each ) do
|
204
|
+
Inversion::Template.config = Inversion::Template::DEFAULT_CONFIG
|
205
|
+
end
|
206
|
+
|
207
|
+
it "is included in the list of configurable objects" do
|
208
|
+
Configurability.configurable_objects.should include( Inversion::Template )
|
209
|
+
end
|
210
|
+
|
211
|
+
it "can be configured using a Configurability::Config object" do
|
212
|
+
config = Configurability::Config.new( %{
|
213
|
+
---
|
214
|
+
templates:
|
215
|
+
ignore_unknown_tags: false
|
216
|
+
debugging_comments: true
|
217
|
+
comment_start: "#"
|
218
|
+
comment_end: ""
|
219
|
+
}.gsub(/^\t{3}/, '') )
|
220
|
+
|
221
|
+
Inversion::Template.configure( config.templates )
|
222
|
+
|
223
|
+
Inversion::Template.config[:ignore_unknown_tags].should be_false()
|
224
|
+
Inversion::Template.config[:debugging_comments].should be_true()
|
225
|
+
Inversion::Template.config[:comment_start].should == '#'
|
226
|
+
Inversion::Template.config[:comment_end].should == ''
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
describe "exception-handling:" do
|
234
|
+
|
235
|
+
before( :each ) do
|
236
|
+
@source = "Some stuff\n<?call obj.raise_exception ?>\nMore stuff"
|
237
|
+
@tmpl = Inversion::Template.new( @source )
|
238
|
+
|
239
|
+
@obj = Object.new
|
240
|
+
def @obj.raise_exception
|
241
|
+
raise "Okay, here's an exception!"
|
242
|
+
end
|
243
|
+
|
244
|
+
@tmpl.obj = @obj
|
245
|
+
end
|
246
|
+
|
247
|
+
it "can be configured to completely ignore exceptions raised while rendering" do
|
248
|
+
@tmpl.options[:on_render_error] = :ignore
|
249
|
+
@tmpl.render.should == "Some stuff\nMore stuff"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "can be configured to insert debugging comments for exceptions raised while rendering" do
|
253
|
+
@tmpl.options[:on_render_error] = :comment
|
254
|
+
@tmpl.render.should ==
|
255
|
+
"Some stuff\n<!-- RuntimeError: Okay, here's an exception! -->More stuff"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "can be configured to propagate exceptions raised while rendering" do
|
259
|
+
@tmpl.options[:on_render_error] = :propagate
|
260
|
+
expect {
|
261
|
+
@tmpl.render
|
262
|
+
}.to raise_exception( RuntimeError, /Okay, here's an exception!/ )
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
end
|
269
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env rspec -cfd -b
|
2
|
+
# vim: set noet nosta sw=4 ts=4 :
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname( __FILE__ ).dirname.parent.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'inversion/tilt'
|
18
|
+
$tilt_support = true
|
19
|
+
rescue LoadError => err
|
20
|
+
warn "Tilt support testing disabled: %p: %s" % [ err.class, err.message ]
|
21
|
+
$tilt_support = false
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Tilt support", :if => $tilt_support do
|
25
|
+
|
26
|
+
before( :all ) do
|
27
|
+
setup_logging( :fatal )
|
28
|
+
end
|
29
|
+
|
30
|
+
it "registers itself with Tilt" do
|
31
|
+
Tilt['layout.tmpl'].should == Inversion::TiltWrapper
|
32
|
+
end
|
33
|
+
|
34
|
+
it "merges locals with template attributes upon evaluation" do
|
35
|
+
File.stub( :binread ).with( 'test.tmpl' ).and_return( '<?attr foo ?>' )
|
36
|
+
Tilt.new( 'test.tmpl' ).render( Object.new, :foo => 'Booyakasha!' ).should == 'Booyakasha!'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "merges the 'scope' object if it responds_to #to_h" do
|
40
|
+
scope = Object.new
|
41
|
+
def scope.to_h; { :message => "Respek!" }; end
|
42
|
+
File.stub( :binread ).with( 'test.tmpl' ).and_return( '<?attr message ?>' )
|
43
|
+
Tilt.new( 'test.tmpl' ).render( scope, {} ).should == 'Respek!'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env rspec -cfd -b
|
2
|
+
# vim: set noet nosta sw=4 ts=4 :
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
basedir = Pathname( __FILE__ ).dirname.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
require 'inversion'
|
16
|
+
|
17
|
+
describe Inversion do
|
18
|
+
|
19
|
+
before( :all ) do
|
20
|
+
@original_logger = Inversion.default_logger
|
21
|
+
@original_log_formatter = Inversion.default_log_formatter
|
22
|
+
setup_logging( :fatal )
|
23
|
+
end
|
24
|
+
|
25
|
+
after( :each ) do
|
26
|
+
Inversion.default_logger = @original_logger
|
27
|
+
Inversion.default_log_formatter = @original_log_formatter
|
28
|
+
reset_logging()
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it "defines a version" do
|
33
|
+
Inversion::VERSION.should =~ /^\d+(\.\d+)*$/
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "version methods" do
|
37
|
+
|
38
|
+
it "returns a version string if asked" do
|
39
|
+
Inversion.version_string.should =~ /\w+ [\d.]+/
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a version string with a build number if asked" do
|
43
|
+
Inversion.version_string(true).should =~ /\w+ [\d.]+ \(build [[:xdigit:]]+\)/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
describe " logging subsystem" do
|
49
|
+
before(:each) do
|
50
|
+
Inversion.reset_logger
|
51
|
+
end
|
52
|
+
|
53
|
+
after(:each) do
|
54
|
+
Inversion.reset_logger
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it "knows if its default logger is replaced" do
|
59
|
+
Inversion.reset_logger
|
60
|
+
Inversion.should be_using_default_logger
|
61
|
+
Inversion.logger = Logger.new( $stderr )
|
62
|
+
Inversion.should_not be_using_default_logger
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has the default logger instance after being reset" do
|
66
|
+
Inversion.logger.should equal( Inversion.default_logger )
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has the default log formatter instance after being reset" do
|
70
|
+
Inversion.logger.formatter.should equal( Inversion.default_log_formatter )
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
describe " logging subsystem with new defaults" do
|
77
|
+
it "uses the new defaults when the logging subsystem is reset" do
|
78
|
+
logger = double( "dummy logger" )
|
79
|
+
formatter = double( "dummy logger" )
|
80
|
+
|
81
|
+
Inversion.default_logger = logger
|
82
|
+
Inversion.default_log_formatter = formatter
|
83
|
+
|
84
|
+
logger.should_receive( :formatter= ).with( formatter )
|
85
|
+
logger.should_receive( :level= ).with( Logger::WARN )
|
86
|
+
|
87
|
+
Inversion.reset_logger
|
88
|
+
Inversion.logger.should equal( logger )
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
|