Changeset 757

Show
Ignore:
Timestamp:
02/23/08 12:14:48 (6 months ago)
Author:
seancribbs
Message:

#610 Bubble up parsing exceptions in development mode. [jonleighton]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/radiant/app/models/page_context.rb

    r628 r757  
    1818    super 
    1919  rescue Exception => e 
    20     raise e if testing
     20    raise e if raise_errors
    2121    @tag_binding_stack.pop unless @tag_binding_stack.last == binding 
    2222    render_error_message(e.message) 
     
    4040    end 
    4141     
    42     def testing
    43       RAILS_ENV == 'test
     42    def raise_errors
     43      RAILS_ENV != 'production
    4444    end 
    4545     
  • trunk/radiant/spec/models/page_context_spec.rb

    r653 r757  
    1010    @parser = Radius::Parser.new(@context, :tag_prefix => 'r') 
    1111  end 
    12      
     12   
     13  it 'should raise an error when it encounters a missing tag' do 
     14    lambda { @parser.parse('<r:missing />') }.should raise_error(StandardTags::TagError) 
     15  end 
     16   
    1317  it 'should initialize correctly' do 
    1418    @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'") 
    2119  end 
    2220   
     
    3836    parse('<r:find url="/another/"><r:if_response>tada!</r:if_response></r:find>').should include("tada!") 
    3937  end 
    40  
    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 
    4838   
    4939  private 
     
    5444   
    5545end 
     46 
     47describe PageContext, "when errors are not being raised" do 
     48  scenario :pages 
     49  test_helper :pages 
     50   
     51  before :each do 
     52    @page = pages(:radius) 
     53    @context = PageContext.new(@page) 
     54    @context.stub!(:raise_errors?).and_return(false) 
     55    @parser = Radius::Parser.new(@context, :tag_prefix => 'r') 
     56  end 
     57   
     58  it 'should output an error when it encounters a missing tag' do 
     59    @parser.parse('<r:missing />').should include("undefined tag `missing'") 
     60  end 
     61   
     62  it 'should pop the stack when an error occurs' do 
     63    @context.current_nesting.should be_empty 
     64    @context.define_tag("error") { |tag| raise "Broken!" } 
     65    @parser.parse("<r:error/>").should match(/Broken\!/) 
     66    @context.current_nesting.should be_empty 
     67  end 
     68end 
  • trunk/radiant/test/unit/page_context_test.rb

    r569 r757  
    1313  def test_initialize 
    1414    assert_equal(@page, @context.page) 
    15   end 
    16    
    17   def test_tag_missing 
    18     assert_raises(StandardTags::TagError) { @parser.parse '<r:missing />' } 
    19     def @context.testing?() false end 
    20     assert_parse_output_match "undefined tag `missing'", '<r:missing />' 
    2115  end 
    2216   
     
    4337  end 
    4438 
    45   def test_exception_pops_stack 
    46     assert_equal '', @context.current_nesting 
    47     @context.define_tag("error") {|tag| raise "Broken!"} 
    48     def @context.testing?(); false; end 
    49     assert_parse_output_match /Broken\!/, "<r:error/>" 
    50     assert_equal '', @context.current_nesting 
    51   end 
    52  
    5339  private 
    5440