summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2012-11-26 20:07:37 +0100
committerGibheer <gibheer@gmail.com>2012-11-26 21:41:09 +0100
commit2a1499479a4317b8cccf7f8c12804165f39675b5 (patch)
treee25e65f44d55c156a1f0541a0cb478a963062f03
parenta913aac8268a7ecbb686fba03a3769a547a37524 (diff)
specs for rendering
-rw-r--r--spec/spec_helper.rb10
-rw-r--r--spec/unit/renderer/render_spec.rb34
2 files changed, 44 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5aae9a9..8a0c7f5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -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
diff --git a/spec/unit/renderer/render_spec.rb b/spec/unit/renderer/render_spec.rb
new file mode 100644
index 0000000..6bb7801
--- /dev/null
+++ b/spec/unit/renderer/render_spec.rb
@@ -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