Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / spec / models / .svn / text-base / page_context_spec.rb.svn-base
blob97e175277d4baff55bf8c9ad9da435d48370dd59
1 require File.dirname(__FILE__) + '/../spec_helper'
3 describe PageContext do
4   scenario :pages
5   test_helper :pages
6   
7   before :each do
8     @page = pages(:radius)
9     @context = PageContext.new(@page)
10     @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
11   end
12     
13   it 'should initialize correctly' do
14     @page.should equal(@context.page)
15   end
16   
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'")
21   end
22   
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(/^$/)
26     
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!") 
30   end
31   
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(/^$/) 
35     
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!")
39   end
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
47   end
48   
49   private
50     
51     def parse(input)
52       @parser.parse(input)
53     end
54   
55 end