Sha256: f170f00b75e1fbae0a350f56cdc2f0d64bf298e543f00d45349c2c8667aa82de

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# encoding: UTF-8

require "spec_helper"

describe Tetra::TemplateManager do
  let(:template_manager) { Tetra::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"))
      expect(File.expand_path(relative_path)).to 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)

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tetra-0.40.0 spec/lib/template_manager_spec.rb