Sha256: 253029664d07908cd15b28f4e7245deb5c9481668fa0a81416469e0951ee72aa

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Stache::Mustache::Handler do
  # ERBHandler = ActionView::Template::Handlers::ERB.new
  # def new_template(body = "<%= hello %>", details = {})
  #   ActionView::Template.new(body, "hello template", ERBHandler, {:virtual_path => "hello"}.merge!(details))
  # end
  before do
    @template = ActionView::Template.new("{{body}}", "hello mustache", Stache::Mustache::Handler, { :virtual_path => "hello_world"})
    @handler = Stache::Mustache::Handler.new
  end

  describe "#mustache_class_from_template" do
    it "returns the appropriate mustache class" do
      class HelloWorld < Stache::Mustache::View; end
      @handler.mustache_class_from_template(@template).should == HelloWorld
      Object.send(:remove_const, :HelloWorld)
    end
    it "is clever about folders and such" do
      @template.stub!(:virtual_path).and_return("profiles/index")
      module Profiles; class Index < Stache::Mustache::View; end; end
      @handler.mustache_class_from_template(@template).should == Profiles::Index
      Object.send(:remove_const, :Profiles)
    end
    it "retuns Stache::Mustache::View if it can't find none" do
      @handler.mustache_class_from_template(@template).should == Stache::Mustache::View
    end
    it "reraises error if loaded mustache_class raises a NameError" do
      @template.stub!(:virtual_path).and_return("profiles/index")
      module Profiles; end
      # Emulate autoload behavior so the error gets raised upon const_get
      Profiles.autoload :Index, File.join(File.dirname(__FILE__), "profile_autoload.rb")

      lambda {
        @handler.mustache_class_from_template(@template)
      }.should raise_error(NameError, "uninitialized constant Profiles::Index::Foo")

      Object.send(:remove_const, :Profiles)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stache-1.0.0.rc spec/stache/mustache/handler_spec.rb
stache-0.9.1 spec/stache/mustache/handler_spec.rb
stache-0.9.0 spec/stache/mustache/handler_spec.rb