Sha256: 5e5554f569438761d36aa601a8d32c22f8a6aefd55d1e44e184ee17c4a4fb3a6

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require File.dirname(__FILE__) + "/../../spec_helper"

module Simply
  describe HTMLBuilder, "with locals" do
    before(:each) do
      @builder = HTMLBuilder.new
    end
    
    it "should have access to a variables value" do
      @builder.locals = { :foo => "bar" }
      @builder.ul do
        li foo
      end

      @builder.to_s.should == "<ul><li>bar</li></ul>"
    end

    it "should convert integer keys to strings" do
      @builder.locals = { :foo => 1 }
      @builder.ul do
        li foo
      end

      @builder.to_s.should == "<ul><li>1</li></ul>"
    end

    it "should be able to use any number of keys" do
      @builder.locals = { :foo => 1, :bar => 2, :baz => 3}
      @builder.ul do
        li foo
        li bar
        li baz
      end

      @builder.to_s.should == "<ul><li>1</li><li>2</li><li>3</li></ul>"
    end

    it "should take locals in the constructor" do
      builder = HTMLBuilder.new(:locals => { :foo => "bar", :bar => "baz" }) do
        ul do
          li foo
          li bar
        end
      end

      builder.to_s.should == "<ul><li>bar</li><li>baz</li></ul>"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smtlaissezfaire-simply-0.1.1 spec/simply/html_builder/locals_spec.rb