aboutsummaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2013-09-03 08:45:55 +0200
committerGibheer <gibheer@gmail.com>2013-09-03 08:45:55 +0200
commita3caf9ac06a4b1aa87ada904ee7089f9976a69b7 (patch)
treef58aadbd2ae9b14b67dd9b8155fd2d2eeeb41745 /spec/unit
parent603dce8628246a17009c3a5f30cb57e21b146672 (diff)
add partial render method
This enables the user to render partial templates to embed them into other templates and the like.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/zero/renderer/render_partial_spec.rb53
-rw-r--r--spec/unit/zero/renderer/render_spec.rb35
2 files changed, 56 insertions, 32 deletions
diff --git a/spec/unit/zero/renderer/render_partial_spec.rb b/spec/unit/zero/renderer/render_partial_spec.rb
new file mode 100644
index 0000000..a4c38c8
--- /dev/null
+++ b/spec/unit/zero/renderer/render_partial_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe Zero::Renderer, '#render' do
+ subject { described_class.new(template_path, type_map) }
+ let(:template_path) { 'spec/fixtures/templates/' }
+ let(:type_map) {{
+ 'html' => ['text/html', 'text/xml', '*/*'],
+ 'json' => ['application/json', 'plain/text']
+ }}
+ let(:html_types) { ['text/html'] }
+ let(:json_types) { ['application/json'] }
+ let(:foo_types) { ['foo/bar', 'bar/foo'] }
+ let(:binding) { SpecTemplateContext.new('foo') }
+
+ it 'returns a tilt template' do
+ expect(subject.render_partial('index', html_types, binding)
+ ).to be_kind_of(String)
+ end
+
+ it 'renders html content' do
+ expect(subject.render_partial('index', html_types, binding)
+ ).to match('success')
+ end
+
+ it 'returns a tilt template for different types' do
+ expect(subject.render_partial('index', json_types, binding)
+ ).to be_kind_of(String)
+ end
+
+ it 'renders json content' do
+ expect(subject.render_partial('index', json_types, binding)
+ ).to match("{text: 'success'}")
+ end
+
+ it 'returns an ArgumentError, if given template does not exist' do
+ expect {
+ subject.render_partial('foobar', html_types, binding)
+ }.to raise_error(ArgumentError, /Template 'foobar' does not exist/)
+ end
+
+ it 'returns an ArgumentError, if no template fits types' do
+ expect {
+ subject.render_partial('index', foo_types, binding)
+ }.to raise_error(
+ ArgumentError, /Template 'index' not found/)
+ end
+
+ it 'uses the context' do
+ expect(subject.render_partial('context', html_types, binding)
+ ).to match('foo')
+
+ end
+end
diff --git a/spec/unit/zero/renderer/render_spec.rb b/spec/unit/zero/renderer/render_spec.rb
index ed11857..6023eb8 100644
--- a/spec/unit/zero/renderer/render_spec.rb
+++ b/spec/unit/zero/renderer/render_spec.rb
@@ -13,38 +13,9 @@ describe Zero::Renderer, '#render' do
let(:binding) { SpecTemplateContext.new('foo') }
context 'with default layout' do
- 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 '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 '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 no template fits types' do
- expect {
- subject.render('index', foo_types, binding)
- }.to raise_error(
- ArgumentError, /Template 'index' not found/)
- end
-
- it 'uses the context' do
- subject.render('context', html_types, binding).should match('foo')
-
+ it 'renders the template' do
+ expect(subject.render('index', html_types, binding)
+ ).to match(/layoutfile[\n]*success/)
end
end