spec/musterb_spec.rb in musterb-0.0.4 vs spec/musterb_spec.rb in musterb-0.0.5

- old
+ new

@@ -1,27 +1,31 @@ require 'erubis' describe Musterb do - def evaluate(template, _binding) - erb = Musterb.to_erb(template) - Erubis::Eruby.new(erb).result(_binding) - end - it "correctly replaces variables" do planet = "World" - evaluate("Hello, {{planet}}!", binding).should eq "Hello, World!" + erb = Musterb.to_erb("Hello, {{planet}}!") + Erubis::Eruby.new(erb).result(binding).should eq "Hello, World!" end it "correctly evaluates if a variable is set" do - set_var = "set" - unset_var = nil - evaluate("{{#set_var}}foo{{/set_var}}", binding).should eq "foo" - evaluate("{{#unset_var}}foo{{/unset_var}}", binding).should eq "" + hash = {:set_var => "set"} + Musterb.render("{{#set_var}}foo{{/set_var}}", hash).should eq "foo" + Musterb.render("{{#unset_var}}foo{{/unset_var}}", hash).should eq "" end it "skips blocks for truthy values" do - set_var = "set" - unset_var = nil - evaluate("{{^set_var}}foo{{/set_var}}", binding).should eq "" - evaluate("{{^unset_var}}foo{{/unset_var}}", binding).should eq "foo" + hash = {:set_var => "set"} + Musterb.render("{{^set_var}}foo{{/set_var}}", hash).should eq "" + Musterb.render("{{^unset_var}}foo{{/unset_var}}", hash).should eq "foo" + end + + it "can pull out deeply nested values" do + hash = {:foo => {:bar => {:baz => 42}}} + Musterb.render("{{foo.bar.baz}}", hash).should eq "42" + end + + it "can iterate over values" do + hash = {:foos => [1, 2, 3]} + Musterb.render("{{#foos}}{{.}}{{/foos}}", hash).should eq "123" end end \ No newline at end of file