File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ def determine_template(options)
26
26
if File . exist? ( options [ :file ] )
27
27
Template ::RawFile . new ( options [ :file ] )
28
28
else
29
- raise ArgumentError , "`render file:` should be given the absolute path to a file. '#{ options [ :file ] } ' was given instead"
29
+ if Pathname . new ( options [ :file ] ) . absolute?
30
+ raise ArgumentError , "File #{ options [ :file ] } does not exist"
31
+ else
32
+ raise ArgumentError , "`render file:` should be given the absolute path to a file. '#{ options [ :file ] } ' was given instead"
33
+ end
30
34
end
31
35
elsif options . key? ( :inline )
32
36
handler = Template . handler_for_extension ( options [ :type ] || "erb" )
Original file line number Diff line number Diff line change @@ -79,7 +79,20 @@ def test_render_file
79
79
80
80
def test_render_file_with_full_path_no_extension
81
81
template_path = File . expand_path ( "../fixtures/test/hello_world" , __dir__ )
82
- assert_raise ( ArgumentError ) { @view . render ( file : template_path ) }
82
+ e = assert_raise ( ArgumentError ) { @view . render ( file : template_path ) }
83
+ assert_match ( /File (.+) does not exist/ , e . message )
84
+ end
85
+
86
+ def test_render_file_with_invalid_full_path
87
+ template_path = File . expand_path ( "../fixtures/test/hello_world_invalid.erb" , __dir__ )
88
+ e = assert_raise ( ArgumentError ) { @view . render ( file : template_path ) }
89
+ assert_match ( /File (.+) does not exist/ , e . message )
90
+ end
91
+
92
+ def test_render_file_with_relative_path
93
+ template_path = "fixtures/test/hello_world.erb"
94
+ e = assert_raise ( ArgumentError ) { @view . render ( file : template_path ) }
95
+ assert_match ( %r{`render file:` should be given the absolute path to a file. (.+) was given instead} , e . message )
83
96
end
84
97
85
98
# Test if :formats, :locale etc. options are passed correctly to the resolvers.
You can’t perform that action at this time.
0 commit comments