Sha256: 203c0dee9a47c7642bc1a95e0dc47c3b3105d759ce361c95ddcfb344f1d5b556

Contents?: true

Size: 1.31 KB

Versions: 21

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe Boxes::Template do
  include FakeFS::SpecHelpers

  let(:env) { Boxes::Environment.new }

  before do
    current_directory = File.expand_path('../../..', __FILE__)

    FileUtils.mkdir_p(current_directory + '/templates')
    FileUtils.mkdir_p(current_directory + '/templates/ubuntu')

    mock_template = <<-EOF
    <% @scripts.each do |s| %>
    <%= s %>
    <% end %>
    EOF

    File.open(current_directory + '/templates/ubuntu/trusty64.erb', 'w') do |f|
      f.puts mock_template
    end
  end

  describe '#initialize' do
    it 'can read in a known template' do
      template = described_class.new(env, 'ubuntu/trusty64')

      expect(template.template).to be_a(String)
    end

    it 'throws an exception if the template is missing' do
      expect do
        described_class.new(env, 'nope/nope')
      end.to raise_error(Boxes::Errors::TemplateNotFoundError)
    end

    it 'stores the template name' do
      template = described_class.new(env, 'ubuntu/trusty64')

      expect(template.name).to eq 'ubuntu/trusty64'
    end
  end

  describe '#render' do
    it 'renders a template with a set of variables' do
      template = described_class.new(env, 'ubuntu/trusty64')
      rendered = template.render(scripts: ['ruby.sh'])

      expect(rendered).to include('ruby.sh')
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
boxes-3.7.0 spec/boxes/template_spec.rb
boxes-3.6.1 spec/boxes/template_spec.rb
boxes-3.6.0 spec/boxes/template_spec.rb
boxes-3.5.0 spec/boxes/template_spec.rb
boxes-3.4.0 spec/boxes/template_spec.rb
boxes-3.3.1 spec/boxes/template_spec.rb
boxes-3.3.0 spec/boxes/template_spec.rb
boxes-3.2.0 spec/boxes/template_spec.rb
boxes-3.1.0 spec/boxes/template_spec.rb
boxes-3.0.0 spec/boxes/template_spec.rb
boxes-2.5.0 spec/boxes/template_spec.rb
boxes-2.4.0 spec/boxes/template_spec.rb
bitswarmbox-1.0.0.pre18 spec/boxes/template_spec.rb
bitswarmbox-1.0.0.pre16 spec/boxes/template_spec.rb
boxes-2.3.0 spec/boxes/template_spec.rb
boxes-2.2.0 spec/boxes/template_spec.rb
boxes-2.1.1 spec/boxes/template_spec.rb
boxes-2.1.0 spec/boxes/template_spec.rb
boxes-2.0.2 spec/boxes/template_spec.rb
boxes-2.0.1 spec/boxes/template_spec.rb