Fixed an uncought exception when run on the Google App Engine infrastructure.

Signed-off-by: Simon Rozet <simon@rozet.name>
This commit is contained in:
Samuel Goebert 2009-04-09 11:17:29 +02:00 committed by Ryan Tomayko
parent 9d67449452
commit b88c0f579a
2 changed files with 18 additions and 1 deletions

View File

@ -635,7 +635,14 @@ module Sinatra
# when no file is specified.
def use_in_file_templates!(file=nil)
file ||= caller_files.first
if data = ::IO.read(file).split('__END__')[1]
begin
data = ::IO.read(file).split('__END__')[1]
rescue
data = nil
end
if data
data.gsub!(/\r\n/, "\n")
template = nil
data.each_line do |line|

View File

@ -75,6 +75,16 @@ class TemplatesTest < Test::Unit::TestCase
assert_equal "this is foo\n\n", @app.templates[:foo]
assert_equal "X\n= yield\nX\n", @app.templates[:layout]
end
test 'use_in_file_templates simply ignores IO errors' do
assert_nothing_raised {
mock_app {
use_in_file_templates!('/foo/bar')
}
}
assert @app.templates.empty?
end
end
__END__