Sha256: e7fb43c27d061b52603f24daac6167697119920b8b6fa64cbf5c2d872bedc3c1

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# encoding: UTF-8

require "spec_helper"

describe Gjp::TemplateManager do
  let(:template_manager) { Gjp::TemplateManager.new }

  describe "#template_path" do
    it "returns the pathname where all templates are stored" do
      relative_path = template_manager.template_path
      expected_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "template"))
      File.expand_path(relative_path).should eq expected_path
    end
  end

  describe "#copy" do
    it "copies a file from template to another dir" do
      destination = Tempfile.new("TemplateManager spec")
      destination_path = destination.path
      destination.unlink

      template_manager.copy(File.join("src", "CONTENTS"), destination_path)

      File.exist?(destination_path)
    end
  end

  describe "#generate" do
    it "compiles a file from a template and a value objects file" do
      template_path = File.join(template_manager.template_path, "test.erb")
      File.open(template_path, "w") { |io| io.puts "Hello <%= world_property %>" }

      destination = Tempfile.new("TemplateManager spec")
      destination_path = destination.path
      destination.unlink

      # binding test class
      class WorldClass
        def world_property
          "World!"
        end

        def public_binding
          binding
        end
      end

      template_manager.generate("test.erb", WorldClass.new.public_binding, destination_path)
      File.unlink(template_path)

      File.read(destination_path).should eq "Hello World!\n"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gjp-0.39.0 spec/lib/template_manager_spec.rb