Sha256: 79008c01d2ceca318463158c32e45b3024eb10bf30a93642cd7b8f21abf9ee3e

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

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

module Simply
  describe HTMLBuilder, "with locals" do
    before(:each) do
      @builder = HTMLBuilder.new(:indented => false)
    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" }, :indented => false) do
        ul do
          li foo
          li bar
        end
      end

      builder.to_s.should == "<ul><li>bar</li><li>baz</li></ul>"
    end
    
    it "should be able to pass in several sets of locals at different times" do
      builder = HTMLBuilder.new(:locals => {:foo => "1"}, :indented => false)
      builder.locals = {:bar => "2"}
      builder.ul do
        li foo
        li bar
      end
      
      builder.to_s.should == "<ul><li>1</li><li>2</li></ul>"
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
smtlaissezfaire-simply-0.2.1 spec/simply/html_builder/locals_spec.rb
simply-0.2.3 spec/simply/html_builder/locals_spec.rb