Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add liquid tests - beer is wet but whisky is wetter

  • Loading branch information...
commit 3aef6c36e6b92566748ae768e0ff019dd8280bd9 1 parent 71228c1
Ryan Tomayko authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 test/spec_tilt_liquid_template.rb
39 test/spec_tilt_liquid_template.rb
View
@@ -18,6 +18,45 @@
template = Tilt::LiquidTemplate.new { "Hey {{ name }}!" }
template.render(nil, :name => 'Joe').should.equal "Hey Joe!"
end
+
+ # Object's passed as "scope" to LiquidTemplate may respond to
+ # #to_h with a Hash. The Hash's contents are merged underneath
+ # Tilt locals.
+ class ExampleLiquidScope
+ def to_h
+ { :beer => 'wet', :whisky => 'wetter' }
+ end
+ end
+
+ it "merges scope Hash in under locals when scope responds to #to_h" do
+ template =
+ Tilt::LiquidTemplate.new {
+ 'Beer is {{ beer }} but Whisky is {{ whisky }}.'
+ }
+ scope = ExampleLiquidScope.new
+ template.render(scope).should.equal "Beer is wet but Whisky is wetter."
+ end
+
+ it "gives locals presendence over scope defined variables" do
+ template =
+ Tilt::LiquidTemplate.new {
+ 'Beer is {{ beer }} but Whisky is {{ whisky }}.'
+ }
+ scope = ExampleLiquidScope.new
+ template.render(scope, :beer => 'great', :whisky => 'greater').
+ should.equal "Beer is great but Whisky is greater."
+ end
+
+ # Object's passed as "scope" to LiquidTemplate that do not
+ # respond to #to_h are silently ignored.
+ class ExampleIgnoredLiquidScope
+ end
+
+ it "does not freak out when scope does not respond to #to_h" do
+ template = Tilt::LiquidTemplate.new { 'Whisky' }
+ scope = ExampleIgnoredLiquidScope.new
+ template.render(scope).should.equal "Whisky"
+ end
end
rescue LoadError => boom
Please sign in to comment.
Something went wrong with that request. Please try again.