specs for rendering
This commit is contained in:
parent
a913aac826
commit
2a1499479a
|
@ -5,8 +5,18 @@ SimpleCov.start do
|
|||
end
|
||||
|
||||
require 'rack'
|
||||
require 'erb'
|
||||
require 'tilt'
|
||||
require 'zero/all'
|
||||
|
||||
class SpecTemplateContext
|
||||
attr_accessor :name
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
end
|
||||
|
||||
class SpecController < Zero::Controller
|
||||
def process; end
|
||||
def render; @response = [200, {'Content-Type' => 'text/html'}, ['foo']]; end
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Zero::Renderer, '#render' do
|
||||
subject { Zero::Renderer.new(template_path) }
|
||||
let(:template_path) { 'foo' }
|
||||
let(:file_list) { ['./foo/welcome/index.html.erb'] }
|
||||
|
||||
shared_examples_for 'the rendering' do
|
||||
before :each do
|
||||
subject.stub(:search_files).and_return(file_list)
|
||||
subject.stub(:template).and_return(Tilt[:erb].new {template} )
|
||||
end
|
||||
|
||||
it "renders the template" do
|
||||
subject.render('welcome/index', 'text/html', binding).should eq(result)
|
||||
end
|
||||
end
|
||||
|
||||
context 'a simple template' do
|
||||
let(:template) { 'success' }
|
||||
let(:binding) { Object.new }
|
||||
let(:result) { template }
|
||||
|
||||
it_behaves_like 'the rendering'
|
||||
end
|
||||
|
||||
context 'a complex template' do
|
||||
let(:template) { 'success <%= name %>' }
|
||||
let(:binding) { SpecTemplateContext.new('bar') }
|
||||
let(:result) { 'success bar' }
|
||||
|
||||
it_behaves_like 'the rendering'
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue