diff --git a/lib/gutenberg/asset.rb b/lib/gutenberg/asset.rb index f6cb67d..d4ce5ee 100644 --- a/lib/gutenberg/asset.rb +++ b/lib/gutenberg/asset.rb @@ -76,7 +76,11 @@ def initialize(path, check_path = nil) def copy(to) subpath = File.basename @path.chomp(File.basename(@path)) FileUtils.mkdir_p "#{to}/#{subpath}" - FileUtils.cp @path, "#{to}/#{subpath}" + begin + FileUtils.cp @path, "#{to}/#{subpath}" + rescue ArgumentError => e + # For when the source and destination are the same + end end end end diff --git a/spec/asset_spec.rb b/spec/asset_spec.rb index 647742b..1aa7f85 100644 --- a/spec/asset_spec.rb +++ b/spec/asset_spec.rb @@ -169,5 +169,27 @@ Gutenberg::Asset.new("images/foo.png").copy "bar" end + + it "allows source and destination to be the same" do + File.stubs(:exists?).returns(true) + YAML.stubs(:load_file).returns({}) + + FileUtils.stubs(:mkdir_p) + FileUtils.stubs(:cp).raises(ArgumentError) + + Gutenberg::Asset.new("images/foo.png").copy "images" + end + + it "raises an exception when the destination is not found" do + File.stubs(:exists?).returns(true) + YAML.stubs(:load_file).returns({}) + + FileUtils.stubs(:mkdir_p) + FileUtils.stubs(:cp).raises(Errno::ENOENT) + + proc { + Gutenberg::Asset.new("images/foo.png").copy("images") + }.must_raise Errno::ENOENT + end end end