Sha256: 3804d0cd297f99ad30753b6b827c6089918ad81b11377f58219fe5c89b8284fb

Contents?: true

Size: 1.76 KB

Versions: 18

Compression:

Stored size: 1.76 KB

Contents

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

class ERubisTest < Test::Unit::TestCase
  def erubis_app(&block)
    mock_app {
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  it 'renders inline ERubis strings' do
    erubis_app { erubis '<%= 1 + 1 %>' }
    assert ok?
    assert_equal '2', body
  end

  it 'renders .erubis files in views path' do
    erubis_app { erubis :hello }
    assert ok?
    assert_equal "Hello World\n", body
  end

  it 'takes a :locals option' do
    erubis_app {
      locals = {:foo => 'Bar'}
      erubis '<%= foo %>', :locals => locals
    }
    assert ok?
    assert_equal 'Bar', body
  end

  it "renders with inline layouts" do
    mock_app {
      layout { 'THIS. IS. <%= yield.upcase %>!' }
      get('/') { erubis 'Sparta' }
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "renders with file layouts" do
    erubis_app {
      erubis 'Hello World', :layout => :layout2
    }
    assert ok?
    assert_equal "ERubis Layout!\nHello World\n", body
  end

  it "renders erubis with blocks" do
    mock_app {
      def container
        @_out_buf << "THIS."
        yield
        @_out_buf << "SPARTA!"
      end
      def is; "IS." end
      get '/' do
        erubis '<% container do %> <%= is %> <% end %>'
      end
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "can be used in a nested fashion for partials and whatnot" do
    mock_app {
      template(:inner) { "<inner><%= 'hi' %></inner>" }
      template(:outer) { "<outer><%= erubis :inner %></outer>" }
      get '/' do
        erubis :outer
      end
    }

    get '/'
    assert ok?
    assert_equal '<outer><inner>hi</inner></outer>', body
  end
end

Version data entries

18 entries across 18 versions & 6 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sinatra-1.0/test/erubis_test.rb
sinatra-base-1.0 test/erubis_test.rb
sinatra-1.1.4 test/erubis_test.rb
sinatra-1.1.3 test/erubis_test.rb
sinatra-1.1.2 test/erubis_test.rb
sinatra-1.2.0.a test/erubis_test.rb
sinatra-1.1.0 test/erubis_test.rb
sinatra-1.1.b test/erubis_test.rb
sinatra-1.1.a test/erubis_test.rb
sinatra-1.0 test/erubis_test.rb
sinatra-1.0.b test/erubis_test.rb
sinatra-bundles-0.1.2 vendor/gems/sinatra-0.10.1/test/erubis_test.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/sinatra-1.0.a/test/erubis_test.rb
sinatra-1.0.a test/erubis_test.rb
sinatra-bundles-0.1.1 vendor/gems/sinatra-0.10.1/test/erubis_test.rb
sinatra-bundles-0.1.0 vendor/gems/sinatra-0.10.1/test/erubis_test.rb
sinatra-bundles-0.0.2 vendor/gems/sinatra-0.10.1/test/erubis_test.rb
darkhelmet-sinatra-0.10.1 test/erubis_test.rb