From 2a0eba79339fe07e6d58916fcf66bea2822de06d Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Sat, 30 May 2009 23:40:45 -0700 Subject: [PATCH] cp_r should also raise an error when it cannot find the source file. --- lib/fakefs.rb | 4 ++++ test/fakefs_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/fakefs.rb b/lib/fakefs.rb index 7b8eccf..2b73439 100644 --- a/lib/fakefs.rb +++ b/lib/fakefs.rb @@ -25,6 +25,10 @@ module FakeFS def cp_r(src, dest) if dir = FileSystem.find(src) FileSystem.add(dest, dir.entry.clone) + else + # This error sucks, but it conforms to the original Ruby + # method. + raise "unknown file type: #{src}" end end diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb index ca96d82..1bc2ed2 100644 --- a/test/fakefs_test.rb +++ b/test/fakefs_test.rb @@ -278,4 +278,12 @@ class FakeFSTest < Test::Unit::TestCase File.open('baz', 'w') {|f| f.write 'quux' } assert_equal 'bar', File.open('foo'){|f| f.read } end + + def test_cp_r_should_raise_error_on_missing_file + # Yes, this error sucks, but it conforms to the original Ruby + # method. + assert_raise(RuntimeError) do + FileUtils.cp_r 'blafgag', 'foo' + end + end end