Sha256: 44d75e1a5bde1f4ef6551fd89a0e05d4a92c92eb4dbe1763e201b4ac5dc4d9b2

Contents?: true

Size: 1.83 KB

Versions: 93

Compression:

Stored size: 1.83 KB

Contents

require File.dirname(__FILE__) + '/helper'

context "Builder" do

  setup do
    Sinatra.application = nil
  end

  context "without layouts" do

    setup do
      Sinatra.application = nil
    end

    specify "should render" do

      get '/no_layout' do
        builder 'xml.instruct!'
      end

      get_it '/no_layout'
      should.be.ok
      body.should == %(<?xml version="1.0" encoding="UTF-8"?>\n)

    end

    specify "should render inline block" do

      get '/no_layout_and_inlined' do
        @name = "Frank & Mary"
        builder do |xml|
          xml.couple @name
        end
      end

      get_it '/no_layout_and_inlined'
      should.be.ok
      body.should == %(<couple>Frank &amp; Mary</couple>\n)

    end

  end



  context "Templates (in general)" do

    setup do
      Sinatra.application = nil
    end

    specify "are read from files if Symbols" do

      get '/from_file' do
        @name = 'Blue'
        builder :foo, :views_directory => File.dirname(__FILE__) + "/views"
      end

      get_it '/from_file'
      should.be.ok
      body.should.equal %(<exclaim>You rock Blue!</exclaim>\n)

    end

    specify "use layout.ext by default if available" do

      get '/' do
        builder :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
      end

      get_it '/'
      should.be.ok
      body.should.equal "<layout>\n<this>is foo!</this>\n</layout>\n"

    end

    specify "renders without layout" do

      get '/' do
        builder :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
      end

      get_it '/'
      should.be.ok
      body.should.equal "<foo>No Layout!</foo>\n"

    end

    specify "raises error if template not found" do

      get '/' do
        builder :not_found
      end

      lambda { get_it '/' }.should.raise(Errno::ENOENT)

    end

  end

end

Version data entries

93 entries across 93 versions & 14 rubygems

Version Path
nbudin-castronaut-0.7.5 vendor/sinatra/compat/builder_test.rb
sinatra-0.9.6 compat/builder_test.rb
sinatra-0.9.5 compat/builder_test.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/sinatra-0.9.4/compat/builder_test.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/builder_test.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.10.17 vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.10.16 vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.10.15 vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
middleman-0.10.14 vendor/gems/gems/sinatra-0.9.4/compat/builder_test.rb
sinatra-0.9.4 compat/builder_test.rb
sinatra-0.9.0 compat/builder_test.rb
sinatra-0.9.0.3 compat/builder_test.rb
sinatra-0.3.0 test/builder_test.rb