From 4d7d3636afe2689d8ed5e7ea8f976441cf99d2e3 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Thu, 28 Jan 2010 07:42:19 -0800 Subject: [PATCH] Revert "remove erubis test (let tilt handle this)" This reverts commit 3ac8cb76da7f91dc93eb533c1b063592cb80f2b9. Oops. I meant to take this out after adding the development dependencies. I still don't think it would be a bad idea to remove the template-engine specific tests from Sinatra, but I think we should do it across all engines, not just erubis. --- test/erubis_test.rb | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/erubis_test.rb diff --git a/test/erubis_test.rb b/test/erubis_test.rb new file mode 100644 index 00000000..447f25fa --- /dev/null +++ b/test/erubis_test.rb @@ -0,0 +1,82 @@ +require File.dirname(__FILE__) + '/helper' +require 'erubis' + +class ERubisTest < Test::Unit::TestCase + def erubis_app(&block) + mock_app { + set :views, File.dirname(__FILE__) + '/views' + get '/', &block + } + get '/' + end + + it 'renders inline ERubis strings' do + erubis_app { erubis '<%= 1 + 1 %>' } + assert ok? + assert_equal '2', body + end + + it 'renders .erubis files in views path' do + erubis_app { erubis :hello } + assert ok? + assert_equal "Hello World\n", body + end + + it 'takes a :locals option' do + erubis_app { + locals = {:foo => 'Bar'} + erubis '<%= foo %>', :locals => locals + } + assert ok? + assert_equal 'Bar', body + end + + it "renders with inline layouts" do + mock_app { + layout { 'THIS. IS. <%= yield.upcase %>!' } + get('/') { erubis 'Sparta' } + } + get '/' + assert ok? + assert_equal 'THIS. IS. SPARTA!', body + end + + it "renders with file layouts" do + erubis_app { + erubis 'Hello World', :layout => :layout2 + } + assert ok? + assert_equal "ERubis Layout!\nHello World\n", body + end + + it "renders erubis with blocks" do + mock_app { + def container + @_out_buf << "THIS." + yield + @_out_buf << "SPARTA!" + end + def is; "IS." end + get '/' do + erubis '<% container do %> <%= is %> <% end %>' + end + } + get '/' + assert ok? + assert_equal 'THIS. IS. SPARTA!', body + end + + it "can be used in a nested fashion for partials and whatnot" do + mock_app { + template(:inner) { "<%= 'hi' %>" } + template(:outer) { "<%= erubis :inner %>" } + get '/' do + erubis :outer + end + } + + get '/' + assert ok? + assert_equal 'hi', body + end +end