require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') module TestHelperModule end describe TestHelperModule do describe "simple block_helper" do before(:each) do class TestHelperModule::TestHelper < BlockHelpers::BlockHelper def hello 'Hi there' end end end it "should make the named helper available" do helper.should respond_to(:test_helper) end it "should work for a simple yielded object" do eval_erb(%( <% test_helper do |h| %>

Before

<%= h.hello %>

After

<% end %> )).should match_html("

Before

Hi there

After

") end end describe "access to other methods" do before(:each) do module TestHelperModule def yoghurt; 'Yoghurt'; end class TestHelper def yog yoghurt[0..2] end end end end it "should give the yielded renderer access to other methods" do eval_erb(%( <% test_helper do |r| %> <%= r.yog %> <% end %> )).should match_html("Yog") end end describe "surrounding the block" do before(:each) do class TestHelperModule::TestHelperSurround < BlockHelpers::BlockHelper def to_s(body) %(

Before

#{body}

After

) end end end it "should surround a simple block" do eval_erb(%( <% test_helper_surround do %> Body here!!! <% end %> )).should match_html("

Before

Body here!!!

After

") end end describe "block helpers with arguments" do before(:each) do class TestHelperModule::TestHelperWithArgs < BlockHelpers::BlockHelper def initialize(id, klass) @id, @klass = id, klass end def hello %(

Hello

) end end end it "should use the args passed in" do eval_erb(%( <% test_helper_with_args('hello', 'there') do |r| %> <%= r.hello %> <% end %> )).should match_html(%(

Hello

)) end end end