diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb index 6e05fb4..15965fe 100644 --- a/lib/fakefs/file.rb +++ b/lib/fakefs/file.rb @@ -379,9 +379,7 @@ module FakeFS end def check_file_existence! - unless @file - raise Errno::ENOENT, "No such file or directory - #{@file}" - end + raise Errno::ENOENT, @path unless @file end def file_creation_mode? diff --git a/test/fake/file_test.rb b/test/fake/file_test.rb index 361f299..7c01671 100644 --- a/test/fake/file_test.rb +++ b/test/fake/file_test.rb @@ -84,13 +84,14 @@ class FakeFileTest < Test::Unit::TestCase assert_equal "bar", @file.content end - def test_gh_34_doesnt_print_path_of_nonexisting_file + def test_raises_an_error_with_the_correct_path + path = "/some/non/existing/file" begin - FakeFS::File.new "/some/non/existing/file" + FakeFS::File.new path msg = nil rescue Errno::ENOENT => e msg = e.message end - assert_match /^No such file or directory - No such file or directory - $/, msg + assert_equal "No such file or directory - #{path}", msg end end