1 require File.dirname(__FILE__) + '/../spec_helper'
3 describe PageContext do
9 @context = PageContext.new(@page)
10 @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
13 it 'should initialize correctly' do
14 @page.should equal(@context.page)
17 it 'should output an error when it encounters a missing tag' do
18 lambda { parse('<r:missing />') }.should raise_error(StandardTags::TagError)
19 def @context.testing?; false end
20 parse('<r:missing />').should include("undefined tag `missing'")
23 it 'should give tags access to the request' do
24 @context.define_tag("if_request") { |tag| tag.expand if tag.locals.page.request }
25 parse('<r:if_request>tada!</r:if_request>').should match(/^$/)
27 @page.request = ActionController::TestRequest.new
28 parse('<r:if_request>tada!</r:if_request>').should include("tada!")
29 parse('<r:find url="/another/"><r:if_request>tada!</r:if_request></r:find>').should include("tada!")
32 it 'should give tags access to the response' do
33 @context.define_tag("if_response") { |tag| tag.expand if tag.locals.page.response }
34 parse('<r:if_response>tada!</r:if_response>').should match(/^$/)
36 @page.response = ActionController::TestResponse.new
37 parse('<r:if_response>tada!</r:if_response>').should include("tada!")
38 parse('<r:find url="/another/"><r:if_response>tada!</r:if_response></r:find>').should include("tada!")
41 it 'should pop the stack when an error occurs' do
42 @context.current_nesting.should be_empty
43 @context.define_tag("error") { |tag| raise "Broken!" }
44 def @context.testing?(); false; end
45 parse("<r:error/>").should match(/Broken\!/)
46 @context.current_nesting.should be_empty