Sha256: 10b786714fbeb07f15a8b7367f9b2693b38c100182469cc76727d814a6a0f9c4

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

describe Musterb::Musterbifier do
  it "does not change vanilla strings" do
    Musterb::Musterbifier.new("Hello, world!").to_erb.should eq "Hello, world!"
  end

  it "replaces mustaches correctly" do
    Musterb::Musterbifier.new("Hello, {{world}}!").to_erb.should eq "Hello, <%== musterb['world'] %>!"
  end

  it "replaces triple staches correctly" do
    Musterb::Musterbifier.new("Hello, {{{world}}}!").to_erb.should eq "Hello, <%= musterb['world'] %>!"
  end

  it "does not escape if it starts with &" do
    Musterb::Musterbifier.new("Hello, {{& world}}!").to_erb.should eq "Hello, <%= musterb['world'] %>!"
  end

  it "replaces blocks correctly" do
    Musterb::Musterbifier.new("{{#cond}}foo{{/cond}}").to_erb.should eq "<% musterb.block_if musterb['cond'] do %>foo<% end %>"
  end

  it "replaces carrot correctly" do
    Musterb::Musterbifier.new("{{^cond}}foo{{/cond}}").to_erb.should eq "<% musterb.block_unless musterb['cond'] do %>foo<% end %>"
  end

  it "replaces comments with nothing" do
    Musterb::Musterbifier.new("{{! foo\n bar}}").to_erb.should eq ""
  end

  it "replaces . with current value" do
    Musterb::Musterbifier.new("{{.}}").to_erb.should eq "<%== musterb.current %>"
  end

  it "replaces foo.bar with a chain" do
    Musterb::Musterbifier.new("{{foo.bar}}").to_erb.should eq "<%== musterb.chain('foo')['bar'] %>"
  end

  it "replaces calls for partials with an exception by default" do
    Musterb::Musterbifier.new("{{> foo}}").to_erb.should eq "<%= raise NotImplementedError, 'Don't know how to render partial: foo' %>"
  end

  it "can be injected with an algorithm for creating partials" do
    render_partial_template = lambda { |p| "render :partial => '#{p}', :current_context => musterb.context" }
    Musterb::Musterbifier.new("{{> foo}}", render_partial_template).to_erb.should eq "<%= render :partial => 'foo', :current_context => musterb.context %>"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
musterb-0.0.7 spec/musterb/musterbifier_spec.rb
musterb-0.0.6 spec/musterb/musterbifier_spec.rb