Extract Task#template code in Template class

This commit is contained in:
Thibault Jouan
2014-10-10 15:48:00 +00:00
parent 6d74e499fa
commit 82879b56b4
7 changed files with 91 additions and 26 deletions

1
spec/fixtures/templates/basic.erb vendored Normal file
View File

@@ -0,0 +1 @@
basic template

1
spec/fixtures/templates/variables.erb vendored Normal file
View File

@@ -0,0 +1 @@
<%= @foo %>

View File

@@ -0,0 +1,33 @@
require 'spec_helper'
module Producer::Core
describe Template do
include FixturesHelpers
let(:path) { 'basic' }
let(:search_path) { fixture_path_for 'templates' }
subject(:template) { described_class.new path, search_path: search_path }
describe '#render' do
it 'renders ERB templates' do
expect(template.render).to eq "basic template\n"
end
context 'when variables are given' do
let(:path) { 'variables' }
it 'declares given variables in ERB render binding' do
expect(template.render foo: 'bar').to eq "bar\n"
end
end
context 'when relative path is requested' do
let(:path) { fixture_path_for('templates/basic').insert 0, './' }
it 'does not enforce `template\' search path' do
expect(template.render).to eq "basic template\n"
end
end
end
end
end