Class: Railscheck::Test::Views

Inherits:
Railscheck::TestCase show all
Defined in:
lib/test/tc_views.rb

Defined Under Namespace

Modules: TempTemplates

Instance Method Summary collapse

Methods inherited from Railscheck::TestCase

#default_test

Instance Method Details

#test_views_can_parseObject

Test that every erb/rhtml file in the project can parse (except vendor plugins/rails).



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/test/tc_views.rb', line 9

def test_views_can_parse
  # Nb. This task is inspired by a snippet by dseverin (http://snippets.dzone.com/posts/show/3397)        
  (Dir["#{RAILS_ROOT}/app/views/**/*.erb", "#{RAILS_ROOT}/app/views/**/*.rhtml"]-version_control_excludes).each do |fname|
    local_source = ERB.new(IO.read(fname), nil, '-').src
    template_source = "def _tmpl\n#{local_source}\nend"
    
    assert_nothing_raised("Syntax error in \"#{fname}\".") do
      begin 
        TempTemplates.module_eval(template_source, fname, 0 )
      rescue SyntaxError => e
        t = ActionView::TemplateError.new("#{RAILS_ROOT}/app/views/", fname, {}, template_source, e)
        raise SyntaxError.new("Error (#{t.message}) on line ##{t.line_number} of #{t.file_name}")
      end  
    end
  end
end