Sha256: c892d0d7ac89fd6158037868626403189d9ca51c84e6b06bad30d30b837e02d2

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

require 'sinatra/base'
require 'erubis'
require 'haml'
require 'slim'

class SpecTemplates < Sinatra::Base 
  set :environment, :test
  set :views, File.join(File.dirname(__FILE__), '..', '..', 'templates')

  helpers Sinatra::ContentFor2
end

describe Sinatra::ContentFor2 do

  def templates
    @templates ||= begin
      r = SpecTemplates.new
      # remove Rack magic
      while !r.kind_of?(SpecTemplates) do
        r = r.instance_variable_get(:@app)
      end
      r
    end
  end

  [ :erb, :haml, :erubis ].each do |engine|
    it "should render #{engine} template" do
      erubis_was = Erubis
      if engine == :erb
        Object.send(:remove_const, :Erubis)
      end
      sr = templates.send(engine, :sub, :layout => false, :eat_errors => false)
      sr.should_not =~ /sub/
      r = templates.send(engine, :main, :layout => false, :eat_errors => false)
      r.should =~ /main/
      r.should =~ /sub/
      if engine == :erb
        Object.const_set(:Erubis, erubis_was)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinatra-content-for2-0.3.alpha1 spec/lib/sinatra/content_for2_spec.rb