Sha256: 2ef7601058197b3e791e6f01f7d186f03f3f4f092e3510b3b748dce0c861f301

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

require 'erubis'

describe Musterb do
  it "correctly replaces variables" do
    planet = "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
    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
    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

  it "escapes html" do
    hash = {:foo => "<br>" }
    Musterb.render("{{foo}}", hash).should eq "&lt;br&gt;"
  end

  it "skips html evaluation with triple stach" do
    hash = {:foo => "<br>" }
    Musterb.render("{{{foo}}}", hash).should eq "<br>"
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
musterb-1.0.1 spec/musterb_spec.rb
musterb-1.0.0 spec/musterb_spec.rb
musterb-0.2.0 spec/musterb_spec.rb
musterb-0.1.2 spec/musterb_spec.rb
musterb-0.1.1 spec/musterb_spec.rb
musterb-0.1.0 spec/musterb_spec.rb
musterb-0.0.7 spec/musterb_spec.rb
musterb-0.0.6 spec/musterb_spec.rb