diff options
| author | Gibheer <gibheer@gmail.com> | 2012-11-27 21:02:07 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2012-11-27 21:02:07 +0100 | 
| commit | 2762f68363d7578ca02b77e4248496c62873d93c (patch) | |
| tree | b4ca0cea3b52f0abadeaa446da30ce48f730578b | |
| parent | 9b941a91911558f631a9327edbae6b4768aa48b9 (diff) | |
better specs for render
| -rw-r--r-- | spec/fixtures/templates/index.html.erb | 1 | ||||
| -rw-r--r-- | spec/fixtures/templates/index.json.erb | 1 | ||||
| -rw-r--r-- | spec/unit/renderer/render_spec.rb | 42 | 
3 files changed, 23 insertions, 21 deletions
| diff --git a/spec/fixtures/templates/index.html.erb b/spec/fixtures/templates/index.html.erb new file mode 100644 index 0000000..2e9ba47 --- /dev/null +++ b/spec/fixtures/templates/index.html.erb @@ -0,0 +1 @@ +success diff --git a/spec/fixtures/templates/index.json.erb b/spec/fixtures/templates/index.json.erb new file mode 100644 index 0000000..535f10a --- /dev/null +++ b/spec/fixtures/templates/index.json.erb @@ -0,0 +1 @@ +{text: 'success'} diff --git a/spec/unit/renderer/render_spec.rb b/spec/unit/renderer/render_spec.rb index 6bb7801..a4064da 100644 --- a/spec/unit/renderer/render_spec.rb +++ b/spec/unit/renderer/render_spec.rb @@ -1,34 +1,34 @@  require 'spec_helper'  describe Zero::Renderer, '#render' do -  subject { Zero::Renderer.new(template_path) } -  let(:template_path) { 'foo' } +  subject { Zero::Renderer.new(template_path, type_map) } +  let(:template_path) { 'spec/fixtures/templates' }    let(:file_list) { ['./foo/welcome/index.html.erb'] } +  let(:type_map) {{ +    'html' => ['text/html', 'text/xml', '*/*'], +    'json' => ['application/json', 'plain/text'] +  }} +  let(:html_types) { ['text/html'] } +  let(:json_types) { ['application/json'] } +  let(:binding) { SpecTemplateContext.new('foo') } -  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 +  before :each do +    subject.read_template_path!    end -  context 'a simple template' do -    let(:template) { 'success' } -    let(:binding) { Object.new } -    let(:result) { template } +  it 'returns a tilt template' do +    subject.render('index', html_types, binding).should be_kind_of(String) +  end -    it_behaves_like 'the rendering' +  it 'renders html content' do +    subject.render('index', html_types, binding).should match('success')    end -  context 'a complex template' do -    let(:template) { 'success <%= name %>' } -    let(:binding) { SpecTemplateContext.new('bar') } -    let(:result) { 'success bar' } +  it 'returns a tilt template for different types' do +    subject.render('index', json_types, binding).should be_kind_of(String) +  end -    it_behaves_like 'the rendering' +  it 'renders json content' do +    subject.render('index', json_types, binding).should match("{text: 'success'}")    end  end | 
