# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the Ruby license. require 'spec/helper' testcase_requires 'liquid' module ProductsFilter def price(integer) sprintf("$%.2d USD", integer / 100.0) end def prettyprint(text) text.gsub( /\*(.*)\*/, '\1' ) end def count(array) array.size end def paragraph(p) "

#{p}

" end end class TCTemplateLiquidController < Ramaze::Controller template_root 'spec/ramaze/template/liquid/' engine :Liquid trait :liquid_options => { :filters => ProductsFilter } def index @hash = {'name' => 'tobi'} end def products @hash = {'products' => products_list, 'section' => 'Gems', 'cool_products' => true} end private def products_list [ {'name' => 'Ruby', 'price' => 1000, 'description' => 'precious gem'}, {'name' => 'Diamond', 'price' => 2000, 'description' => 'even more precious gem'}, ] end end describe "Liquid" do ramaze(:mapping => {'/' => TCTemplateLiquidController}) it "index" do get('/').body.strip.should == "hi tobi" end it "products" do o = get('/products') o = o.body.split("\n").map{|l| l.strip!; l.empty? ? nil : l}.compact.join("\n") o.should == %{ products

There are currently 2 products in the Gems catalog

Cool products :) }.split("\n").map{|l| l.strip!; l.empty? ? nil : l}.compact.join("\n") end end