inversion 0.12.3 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -1
- data.tar.gz.sig +0 -0
- data/ChangeLog +305 -9
- data/Examples.rdoc +134 -0
- data/GettingStarted.rdoc +44 -0
- data/Guide.rdoc +47 -0
- data/History.rdoc +15 -0
- data/Manifest.txt +7 -2
- data/README.rdoc +9 -10
- data/Rakefile +23 -10
- data/Tags.rdoc +561 -0
- data/lib/inversion.rb +2 -2
- data/lib/inversion/renderstate.rb +46 -11
- data/lib/inversion/template.rb +85 -7
- data/lib/inversion/template/attrtag.rb +1 -1
- data/lib/inversion/template/begintag.rb +8 -8
- data/lib/inversion/template/fragmenttag.rb +60 -0
- data/lib/inversion/template/rescuetag.rb +1 -1
- data/spec/{lib/helpers.rb → helpers.rb} +7 -30
- data/spec/inversion/mixins_spec.rb +55 -65
- data/spec/inversion/monkeypatches_spec.rb +2 -12
- data/spec/inversion/parser_spec.rb +34 -44
- data/spec/inversion/renderstate_spec.rb +123 -69
- data/spec/inversion/sinatra_spec.rb +6 -19
- data/spec/inversion/template/attrtag_spec.rb +56 -76
- data/spec/inversion/template/begintag_spec.rb +24 -41
- data/spec/inversion/template/calltag_spec.rb +1 -18
- data/spec/inversion/template/codetag_spec.rb +6 -24
- data/spec/inversion/template/commenttag_spec.rb +9 -27
- data/spec/inversion/template/configtag_spec.rb +5 -16
- data/spec/inversion/template/containertag_spec.rb +4 -21
- data/spec/inversion/template/defaulttag_spec.rb +6 -23
- data/spec/inversion/template/elsetag_spec.rb +9 -26
- data/spec/inversion/template/elsiftag_spec.rb +7 -24
- data/spec/inversion/template/endtag_spec.rb +6 -23
- data/spec/inversion/template/escapetag_spec.rb +10 -25
- data/spec/inversion/template/fortag_spec.rb +20 -37
- data/spec/inversion/template/fragmenttag_spec.rb +40 -0
- data/spec/inversion/template/iftag_spec.rb +23 -40
- data/spec/inversion/template/importtag_spec.rb +8 -25
- data/spec/inversion/template/includetag_spec.rb +27 -42
- data/spec/inversion/template/node_spec.rb +6 -15
- data/spec/inversion/template/pptag_spec.rb +10 -23
- data/spec/inversion/template/publishtag_spec.rb +4 -21
- data/spec/inversion/template/rescuetag_spec.rb +12 -29
- data/spec/inversion/template/subscribetag_spec.rb +8 -25
- data/spec/inversion/template/tag_spec.rb +24 -37
- data/spec/inversion/template/textnode_spec.rb +8 -24
- data/spec/inversion/template/timedeltatag_spec.rb +31 -43
- data/spec/inversion/template/unlesstag_spec.rb +7 -24
- data/spec/inversion/template/uriencodetag_spec.rb +6 -23
- data/spec/inversion/template/yieldtag_spec.rb +3 -20
- data/spec/inversion/template_spec.rb +155 -108
- data/spec/inversion/tilt_spec.rb +7 -16
- data/spec/inversion_spec.rb +7 -22
- metadata +63 -40
- metadata.gz.sig +0 -0
- data/spec/lib/constants.rb +0 -9
@@ -1,29 +1,12 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/calltag'
|
16
7
|
|
17
8
|
describe Inversion::Template::CallTag do
|
18
9
|
|
19
|
-
before( :all ) do
|
20
|
-
setup_logging( :fatal )
|
21
|
-
end
|
22
|
-
|
23
|
-
after( :all ) do
|
24
|
-
reset_logging()
|
25
|
-
end
|
26
|
-
|
27
10
|
# Since call is just an alias, the attrtag_spec already tests all of
|
28
11
|
# this.
|
29
12
|
|
@@ -1,32 +1,15 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/codetag'
|
16
7
|
|
17
8
|
describe Inversion::Template::CodeTag do
|
18
9
|
|
19
|
-
before( :all ) do
|
20
|
-
setup_logging( :fatal )
|
21
|
-
end
|
22
|
-
|
23
|
-
after( :all ) do
|
24
|
-
reset_logging()
|
25
|
-
end
|
26
|
-
|
27
10
|
|
28
11
|
it "is an abstract class" do
|
29
|
-
Inversion::Template::Tag.
|
12
|
+
expect( Inversion::Template::Tag ).to be < Inversion::AbstractClass
|
30
13
|
end
|
31
14
|
|
32
15
|
|
@@ -37,13 +20,12 @@ describe Inversion::Template::CodeTag do
|
|
37
20
|
tag_pattern "$(ident)" do |tag, match|
|
38
21
|
:foo
|
39
22
|
end
|
40
|
-
|
41
23
|
end
|
42
24
|
|
43
|
-
subclass.tag_patterns.
|
44
|
-
subclass.tag_patterns.first[0].
|
45
|
-
|
46
|
-
subclass.tag_patterns.first[1].call(
|
25
|
+
expect( subclass.tag_patterns.size ).to eq( 1 )
|
26
|
+
expect( subclass.tag_patterns.first[0] ).
|
27
|
+
to be_an_instance_of( Inversion::Template::CodeTag::TokenPattern )
|
28
|
+
expect( subclass.tag_patterns.first[1].call(:dummy, :king_dummy) ).to eq( :foo )
|
47
29
|
end
|
48
30
|
|
49
31
|
end
|
@@ -1,17 +1,8 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/commenttag'
|
16
7
|
require 'inversion/template/attrtag'
|
17
8
|
require 'inversion/template/textnode'
|
@@ -19,25 +10,16 @@ require 'inversion/renderstate'
|
|
19
10
|
|
20
11
|
describe Inversion::Template::CommentTag do
|
21
12
|
|
22
|
-
before( :all ) do
|
23
|
-
setup_logging( :fatal )
|
24
|
-
end
|
25
|
-
|
26
|
-
after( :all ) do
|
27
|
-
reset_logging()
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
13
|
it "allows any free-form text in its body" do
|
32
14
|
# <?comment Disabled for now ?>...<?end?>
|
33
|
-
Inversion::Template::CommentTag.new(
|
34
|
-
|
15
|
+
expect( Inversion::Template::CommentTag.new('Disabled for now') ).
|
16
|
+
to be_a( Inversion::Template::CommentTag )
|
35
17
|
end
|
36
18
|
|
37
19
|
it "allows an empty body" do
|
38
20
|
# <?comment ?>...<?end?>
|
39
|
-
Inversion::Template::CommentTag.new(
|
40
|
-
|
21
|
+
expect( Inversion::Template::CommentTag.new('') ).
|
22
|
+
to be_a( Inversion::Template::CommentTag )
|
41
23
|
end
|
42
24
|
|
43
25
|
|
@@ -49,7 +31,7 @@ describe Inversion::Template::CommentTag do
|
|
49
31
|
tag << Inversion::Template::AttrTag.new( 'foo', 1, 9 )
|
50
32
|
tag << Inversion::Template::TextNode.new( ' -', 1, 12 )
|
51
33
|
|
52
|
-
tag.as_comment_body.
|
34
|
+
expect( tag.as_comment_body ).to eq( 'Commented out 3 nodes on line 1' )
|
53
35
|
end
|
54
36
|
|
55
37
|
|
@@ -61,8 +43,8 @@ describe Inversion::Template::CommentTag do
|
|
61
43
|
tag << Inversion::Template::AttrTag.new( 'foo', 3, 0 )
|
62
44
|
tag << Inversion::Template::TextNode.new( '- ', 4, 0 )
|
63
45
|
|
64
|
-
tag.as_comment_body.
|
65
|
-
"We couldn't have done it without me"
|
46
|
+
expect( tag.as_comment_body ).
|
47
|
+
to eq( "Commented out 3 nodes from line 2 to 4: We couldn't have done it without me" )
|
66
48
|
end
|
67
49
|
|
68
50
|
|
@@ -75,7 +57,7 @@ describe Inversion::Template::CommentTag do
|
|
75
57
|
tag << Inversion::Template::AttrTag.new( 'foo' )
|
76
58
|
tag << Inversion::Template::TextNode.new( ' -' )
|
77
59
|
|
78
|
-
tag.render(
|
60
|
+
expect( tag.render(render_state) ).to eq( '' )
|
79
61
|
end
|
80
62
|
|
81
63
|
end
|
@@ -1,29 +1,18 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/configtag'
|
16
7
|
|
17
8
|
describe Inversion::Template::ConfigTag do
|
18
9
|
|
19
10
|
before( :all ) do
|
20
|
-
setup_logging( :fatal )
|
21
11
|
Inversion::Template.template_paths << 'spec/data'
|
22
12
|
end
|
23
13
|
|
24
14
|
after( :all ) do
|
25
15
|
Inversion::Template.template_paths.delete( 'spec/data' )
|
26
|
-
reset_logging()
|
27
16
|
end
|
28
17
|
|
29
18
|
|
@@ -31,7 +20,7 @@ describe Inversion::Template::ConfigTag do
|
|
31
20
|
# <?config comment_end: */ ?>
|
32
21
|
it "can contain a single configuration setting" do
|
33
22
|
tag = Inversion::Template::ConfigTag.new( 'comment_start: /*' )
|
34
|
-
tag.options.
|
23
|
+
expect( tag.options ).to eq({ :comment_start => '/*' })
|
35
24
|
end
|
36
25
|
|
37
26
|
# <?config
|
@@ -67,13 +56,13 @@ describe Inversion::Template::ConfigTag do
|
|
67
56
|
tag = Inversion::Template::ConfigTag.new( 'comment_start: /*' )
|
68
57
|
state = Inversion::RenderState.new
|
69
58
|
|
70
|
-
expect( tag.render(state) ).to
|
59
|
+
expect( tag.render(state) ).to be_nil
|
71
60
|
end
|
72
61
|
|
73
62
|
it "raises an error on an empty body" do
|
74
63
|
expect {
|
75
64
|
Inversion::Template::ConfigTag.new( '' )
|
76
|
-
}.to
|
65
|
+
}.to raise_error( Inversion::ParseError, /empty config settings/i )
|
77
66
|
end
|
78
67
|
|
79
68
|
|
@@ -87,7 +76,7 @@ describe Inversion::Template::ConfigTag do
|
|
87
76
|
TEMPLATE
|
88
77
|
expect {
|
89
78
|
Inversion::Template.new( source, :ignore_unknown_tags => true )
|
90
|
-
}.to
|
79
|
+
}.to raise_error( Inversion::ParseError, /unknown tag "what"/i )
|
91
80
|
end
|
92
81
|
|
93
82
|
it "can turn on debugging comments in rendered output" do
|
@@ -1,29 +1,12 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/containertag'
|
16
7
|
|
17
8
|
describe Inversion::Template::ContainerTag do
|
18
9
|
|
19
|
-
before( :all ) do
|
20
|
-
setup_logging( :fatal )
|
21
|
-
end
|
22
|
-
|
23
|
-
after( :all ) do
|
24
|
-
reset_logging()
|
25
|
-
end
|
26
|
-
|
27
10
|
context "instances of including classes" do
|
28
11
|
|
29
12
|
before( :each ) do
|
@@ -34,17 +17,17 @@ describe Inversion::Template::ContainerTag do
|
|
34
17
|
end
|
35
18
|
|
36
19
|
it "are container tags" do
|
37
|
-
@tag.
|
20
|
+
expect( @tag ).to be_a_container()
|
38
21
|
end
|
39
22
|
|
40
23
|
it "contain a subnodes array" do
|
41
|
-
@tag.subnodes.
|
24
|
+
expect( @tag.subnodes ).to be_an( Array )
|
42
25
|
end
|
43
26
|
|
44
27
|
it "can have other nodes appended to them" do
|
45
28
|
other_node = Inversion::Template::TextNode.new( "foom" )
|
46
29
|
@tag << other_node
|
47
|
-
@tag.subnodes.
|
30
|
+
expect( @tag.subnodes ).to include( other_node )
|
48
31
|
end
|
49
32
|
|
50
33
|
end
|
@@ -1,58 +1,41 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/defaulttag'
|
16
7
|
|
17
8
|
describe Inversion::Template::DefaultTag do
|
18
9
|
|
19
|
-
before( :all ) do
|
20
|
-
setup_logging( :fatal )
|
21
|
-
end
|
22
|
-
|
23
|
-
after( :all ) do
|
24
|
-
reset_logging()
|
25
|
-
end
|
26
|
-
|
27
10
|
|
28
11
|
it "sets a template attribute to a default value" do
|
29
12
|
tmpl = Inversion::Template.new( '<?default foo to 11883 ?><?attr foo ?>' )
|
30
|
-
tmpl.render.
|
13
|
+
expect( tmpl.render ).to eq( '11883' )
|
31
14
|
end
|
32
15
|
|
33
16
|
it "doesn't override a value set on the template as an attribute" do
|
34
17
|
tmpl = Inversion::Template.new( '<?default foo to 11883 ?><?attr foo ?>' )
|
35
18
|
tmpl.foo = 'bar'
|
36
|
-
tmpl.render.
|
19
|
+
expect( tmpl.render ).to eq( 'bar' )
|
37
20
|
end
|
38
21
|
|
39
22
|
it "can set a template attribute to the result of calling a methodchain" do
|
40
23
|
tmpl = Inversion::Template.
|
41
24
|
new( '<?default width to foo.length ?><?attr foo ?>:<?attr width ?>' )
|
42
25
|
tmpl.foo = 'bar'
|
43
|
-
tmpl.render.
|
26
|
+
expect( tmpl.render ).to eq( 'bar:3' )
|
44
27
|
end
|
45
28
|
|
46
29
|
it "can format the default value" do
|
47
30
|
tmpl = Inversion::Template.
|
48
31
|
new( '<?default width to "[%02d]" % [ foo.length ] ?><?attr foo ?>:<?attr width ?>' )
|
49
32
|
tmpl.foo = 'bar'
|
50
|
-
tmpl.render.
|
33
|
+
expect( tmpl.render ).to eq( 'bar:[03]' )
|
51
34
|
end
|
52
35
|
|
53
36
|
it "can render itself as a comment for template debugging" do
|
54
37
|
tag = Inversion::Template::DefaultTag.new( 'width to foo.length' )
|
55
|
-
tag.as_comment_body.
|
38
|
+
expect( tag.as_comment_body ).to eq( "Default 'width': { template.foo.length }" )
|
56
39
|
end
|
57
40
|
|
58
41
|
end
|
@@ -1,17 +1,8 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/iftag'
|
16
7
|
require 'inversion/template/elsetag'
|
17
8
|
require 'inversion/template/unlesstag'
|
@@ -21,14 +12,6 @@ require 'inversion/renderstate'
|
|
21
12
|
|
22
13
|
describe Inversion::Template::ElseTag do
|
23
14
|
|
24
|
-
before( :all ) do
|
25
|
-
setup_logging( :fatal )
|
26
|
-
end
|
27
|
-
|
28
|
-
after( :all ) do
|
29
|
-
reset_logging()
|
30
|
-
end
|
31
|
-
|
32
15
|
it "handles a non-existant body" do
|
33
16
|
Inversion::Template::ElseTag.new( nil )
|
34
17
|
end
|
@@ -42,7 +25,7 @@ describe Inversion::Template::ElseTag do
|
|
42
25
|
|
43
26
|
parserstate << iftag << elsetag << endtag
|
44
27
|
|
45
|
-
parserstate.tree.
|
28
|
+
expect( parserstate.tree ).to eq( [ iftag, endtag ] )
|
46
29
|
end
|
47
30
|
|
48
31
|
it "can be appended to an 'unless' tag" do
|
@@ -54,8 +37,8 @@ describe Inversion::Template::ElseTag do
|
|
54
37
|
|
55
38
|
parserstate << unlesstag << elsetag << endtag
|
56
39
|
|
57
|
-
parserstate.tree.
|
58
|
-
unlesstag.subnodes.
|
40
|
+
expect( parserstate.tree ).to eq( [ unlesstag, endtag ] )
|
41
|
+
expect( unlesstag.subnodes ).to include( elsetag )
|
59
42
|
end
|
60
43
|
|
61
44
|
it "can be appended to a 'comment' tag" do
|
@@ -67,8 +50,8 @@ describe Inversion::Template::ElseTag do
|
|
67
50
|
|
68
51
|
parserstate << commenttag << elsetag << endtag
|
69
52
|
|
70
|
-
parserstate.tree.
|
71
|
-
commenttag.subnodes.
|
53
|
+
expect( parserstate.tree ).to eq( [ commenttag, endtag ] )
|
54
|
+
expect( commenttag.subnodes ).to include( elsetag )
|
72
55
|
end
|
73
56
|
|
74
57
|
it "raises an error if it's about to be appended to anything other than an 'if', 'unless', " +
|
@@ -79,7 +62,7 @@ describe Inversion::Template::ElseTag do
|
|
79
62
|
|
80
63
|
expect {
|
81
64
|
parserstate << Inversion::Template::ElseTag.new
|
82
|
-
}.to
|
65
|
+
}.to raise_error( Inversion::ParseError, /'for' tags can't have 'else' clauses/i )
|
83
66
|
end
|
84
67
|
|
85
68
|
|
@@ -89,14 +72,14 @@ describe Inversion::Template::ElseTag do
|
|
89
72
|
|
90
73
|
expect {
|
91
74
|
parserstate << Inversion::Template::ElseTag.new
|
92
|
-
}.to
|
75
|
+
}.to raise_error( Inversion::ParseError, /orphaned 'else' tag/i )
|
93
76
|
end
|
94
77
|
|
95
78
|
|
96
79
|
it "doesn't render as anything by itself" do
|
97
80
|
renderstate = Inversion::RenderState.new
|
98
81
|
tag = Inversion::Template::ElseTag.new
|
99
|
-
tag.render(
|
82
|
+
expect( tag.render(renderstate) ).to be_nil()
|
100
83
|
end
|
101
84
|
|
102
85
|
end
|
@@ -1,17 +1,8 @@
|
|
1
1
|
#!/usr/bin/env rspec -cfd -b
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname( __FILE__ ).dirname.parent.parent.parent
|
7
|
-
libdir = basedir + 'lib'
|
4
|
+
require_relative '../../helpers'
|
8
5
|
|
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
6
|
require 'inversion/template/iftag'
|
16
7
|
require 'inversion/template/elsiftag'
|
17
8
|
require 'inversion/template/unlesstag'
|
@@ -20,14 +11,6 @@ require 'inversion/renderstate'
|
|
20
11
|
|
21
12
|
describe Inversion::Template::ElsifTag do
|
22
13
|
|
23
|
-
before( :all ) do
|
24
|
-
setup_logging( :fatal )
|
25
|
-
end
|
26
|
-
|
27
|
-
after( :all ) do
|
28
|
-
reset_logging()
|
29
|
-
end
|
30
|
-
|
31
14
|
|
32
15
|
it "can be appended to an 'if' tag" do
|
33
16
|
template = double( "template object" )
|
@@ -38,7 +21,7 @@ describe Inversion::Template::ElsifTag do
|
|
38
21
|
|
39
22
|
parserstate << iftag << elsetag << endtag
|
40
23
|
|
41
|
-
parserstate.tree.
|
24
|
+
expect( parserstate.tree ).to eq( [ iftag, endtag ] )
|
42
25
|
end
|
43
26
|
|
44
27
|
it "can be appended to a 'comment' tag" do
|
@@ -50,8 +33,8 @@ describe Inversion::Template::ElsifTag do
|
|
50
33
|
|
51
34
|
parserstate << commenttag << elsetag << endtag
|
52
35
|
|
53
|
-
parserstate.tree.
|
54
|
-
commenttag.subnodes.
|
36
|
+
expect( parserstate.tree ).to eq( [ commenttag, endtag ] )
|
37
|
+
expect( commenttag.subnodes ).to include( elsetag )
|
55
38
|
end
|
56
39
|
|
57
40
|
it "raises an error if it's about to be appended to anything other than an 'if' or 'comment' tag" do
|
@@ -61,7 +44,7 @@ describe Inversion::Template::ElsifTag do
|
|
61
44
|
|
62
45
|
expect {
|
63
46
|
parserstate << Inversion::Template::ElsifTag.new( 'bar' )
|
64
|
-
}.to
|
47
|
+
}.to raise_error( Inversion::ParseError, /'unless' tags can't have 'elsif' clauses/i )
|
65
48
|
end
|
66
49
|
|
67
50
|
|
@@ -71,14 +54,14 @@ describe Inversion::Template::ElsifTag do
|
|
71
54
|
|
72
55
|
expect {
|
73
56
|
parserstate << Inversion::Template::ElsifTag.new( 'bar' )
|
74
|
-
}.to
|
57
|
+
}.to raise_error( Inversion::ParseError, /orphaned 'elsif' tag/i )
|
75
58
|
end
|
76
59
|
|
77
60
|
|
78
61
|
it "renders as its attribute value if it's a simple attribute" do
|
79
62
|
renderstate = Inversion::RenderState.new( :bar => :the_attribute_value )
|
80
63
|
tag = Inversion::Template::ElsifTag.new( 'bar' )
|
81
|
-
tag.evaluate( renderstate ).
|
64
|
+
expect( tag.evaluate( renderstate ) ).to eq( :the_attribute_value )
|
82
65
|
end
|
83
66
|
|
84
67
|
end
|