aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/templates/special_layout.html.erb3
-rw-r--r--spec/unit/zero/renderer/initialize_spec.rb11
-rw-r--r--spec/unit/zero/renderer/read_template_path_bang_spec.rb16
-rw-r--r--spec/unit/zero/renderer/render_spec.rb71
-rw-r--r--spec/unit/zero/renderer/template_path.rb8
-rw-r--r--spec/unit/zero/renderer/templates_spec.rb13
-rw-r--r--spec/unit/zero/renderer/type_map_spec.rb13
7 files changed, 68 insertions, 67 deletions
diff --git a/spec/fixtures/templates/special_layout.html.erb b/spec/fixtures/templates/special_layout.html.erb
new file mode 100644
index 0000000..4288509
--- /dev/null
+++ b/spec/fixtures/templates/special_layout.html.erb
@@ -0,0 +1,3 @@
+special layout loaded
+
+<%= yield %>
diff --git a/spec/unit/zero/renderer/initialize_spec.rb b/spec/unit/zero/renderer/initialize_spec.rb
new file mode 100644
index 0000000..39d7302
--- /dev/null
+++ b/spec/unit/zero/renderer/initialize_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Zero::Renderer, '#initialize' do
+ subject { described_class.new(template_path, type_map) }
+ let(:template_path) { 'foo/' }
+ let(:type_map) { {'html' => ['text/html'] } }
+
+ its(:path) { should be(template_path) }
+ its(:layout) { should match(/layout/) }
+ its(:types) { should be(type_map) }
+end
diff --git a/spec/unit/zero/renderer/read_template_path_bang_spec.rb b/spec/unit/zero/renderer/read_template_path_bang_spec.rb
deleted file mode 100644
index 9a2f875..0000000
--- a/spec/unit/zero/renderer/read_template_path_bang_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'spec_helper'
-
-describe Zero::Renderer, '#read_template_path!' do
- subject { Zero::Renderer.new(template_path, type_map) }
- let(:template_path) { 'spec/fixtures/templates/' }
- let(:type_map) { {'html' => ['text/html']} }
- let(:result) { {
- 'text/html' => template_path + 'index.html.erb',
- 'json' => template_path + 'index.json.erb'
- } }
-
- it "loads the templates" do
- subject.read_template_path!
- expect(subject.templates['index']).to eq(result)
- end
-end
diff --git a/spec/unit/zero/renderer/render_spec.rb b/spec/unit/zero/renderer/render_spec.rb
index 3270ac3..ed11857 100644
--- a/spec/unit/zero/renderer/render_spec.rb
+++ b/spec/unit/zero/renderer/render_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Zero::Renderer, '#render' do
- subject { Zero::Renderer.new(template_path, type_map) }
+ subject { described_class.new(template_path, type_map) }
let(:template_path) { 'spec/fixtures/templates/' }
let(:type_map) {{
'html' => ['text/html', 'text/xml', '*/*'],
@@ -12,43 +12,54 @@ describe Zero::Renderer, '#render' do
let(:foo_types) { ['foo/bar', 'bar/foo'] }
let(:binding) { SpecTemplateContext.new('foo') }
- before :each do
- subject.read_template_path!
- end
+ context 'with default layout' do
+ it 'returns a tilt template' do
+ subject.render('index', html_types, binding).should be_kind_of(String)
+ end
- it 'returns a tilt template' do
- subject.render('index', html_types, binding).should be_kind_of(String)
- end
+ it 'renders html content' do
+ subject.render('index', html_types, binding).should match('success')
+ end
- it 'renders html content' do
- subject.render('index', html_types, binding).should match('success')
- end
+ it 'returns a tilt template for different types' do
+ subject.render('index', json_types, binding).should be_kind_of(String)
+ end
- it 'returns a tilt template for different types' do
- subject.render('index', json_types, binding).should be_kind_of(String)
- end
+ it 'renders json content' do
+ subject.render('index', json_types, binding).should match("{text: 'success'}")
+ end
- it 'renders json content' do
- subject.render('index', json_types, binding).should match("{text: 'success'}")
- end
+ it 'returns an ArgumentError, if given template does not exist' do
+ expect {
+ subject.render('foobar', html_types, binding)
+ }.to raise_error(ArgumentError, /Template 'foobar' does not exist/)
+ end
- it 'returns an ArgumentError, if given template does not exist' do
- expect {
- subject.render('foobar', html_types, binding)
- }.to raise_error(ArgumentError, "No template found for 'foobar'!")
- end
+ it 'returns an ArgumentError, if no template fits types' do
+ expect {
+ subject.render('index', foo_types, binding)
+ }.to raise_error(
+ ArgumentError, /Template 'index' not found/)
+ end
- it 'returns an ArgumentError, if no template fits types' do
- expect {
- subject.render('index', foo_types, binding)
- }.to raise_error(
- ArgumentError,
- "No template found for any of this types #{foo_types.join ', '}!"
- )
+ it 'uses the context' do
+ subject.render('context', html_types, binding).should match('foo')
+
+ end
end
- it 'uses the context' do
- subject.render('context', html_types, binding).should match('foo')
+ context 'with special layout' do
+ subject { described_class.new(template_path, layout, type_map) }
+ let(:layout) { 'special_layout' }
+
+ it 'uses the layout for rendering' do
+ expect(subject.render('index', html_types, binding)
+ ).to match(/layout loaded/)
+ end
+ it 'renders the template into the layout' do
+ expect(subject.render('index', html_types, binding)
+ ).to match(/success/)
+ end
end
end
diff --git a/spec/unit/zero/renderer/template_path.rb b/spec/unit/zero/renderer/template_path.rb
deleted file mode 100644
index 261faa8..0000000
--- a/spec/unit/zero/renderer/template_path.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'spec_helper'
-
-describe Zero::Renderer, '#template_path' do
- subject { Zero::Renderer.new(template_path) }
- let(:template_path) { 'foo' }
-
- its(:type_map) { should be(template_path) }
-end
diff --git a/spec/unit/zero/renderer/templates_spec.rb b/spec/unit/zero/renderer/templates_spec.rb
new file mode 100644
index 0000000..f86961b
--- /dev/null
+++ b/spec/unit/zero/renderer/templates_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Zero::Renderer, '#templates' do
+ let(:object) { described_class.new(template_path, types) }
+ subject { object.templates }
+
+ let(:template_path) { 'spec/fixtures/templates/' }
+ let(:types) { {'html' => ['text/html']} }
+
+ it 'loads the template tree' do
+ expect(subject).to be_kind_of(Zero::Renderer::TemplateFinder)
+ end
+end
diff --git a/spec/unit/zero/renderer/type_map_spec.rb b/spec/unit/zero/renderer/type_map_spec.rb
deleted file mode 100644
index 290e579..0000000
--- a/spec/unit/zero/renderer/type_map_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'spec_helper'
-
-describe Zero::Renderer, '#type_map' do
- subject { Zero::Renderer.new(template_path, type_map) }
- let(:template_path) { 'foo' }
- let(:type_map) { {'html' => ['text/html']} }
-
- its(:type_map) { should be(type_map) }
-
- it 'returns an empty Hash, if type_map is not set while initialization' do
- Zero::Renderer.new(template_path).type_map.should eq({})
- end
-end