Commits

Kevin Berridge committed 47a2cc4

added tests for bad paths in PrjfileFinder

Comments (0)

Files changed (2)

lib/prjfile_finder.rb

 
 class PrjfileFinder
   def find_from(file)
-    dir = File.dirname file
-    Dir.chdir dir
     begin
-      matches = Dir.glob('*.csproj')
-      return File.absolute_path(matches[0]) if matches.length > 0
+      dir = File.dirname file
+      Dir.chdir dir
+      begin
+        matches = Dir.glob('*.csproj')
+        return File.absolute_path(matches[0]) if matches.length > 0
 
-      lst_dir = Dir.pwd
-      Dir.chdir '..'
-    end while lst_dir != Dir.pwd
+        lst_dir = Dir.pwd
+        Dir.chdir '..'
+      end while lst_dir != Dir.pwd
 
-    return nil
+      return nil
+    rescue
+      return nil
+    end
   end
 end

spec/prjfile_finder_spec.rb

     found = finder.find_from './prjsync/testA/testB/fakefile.cs'
     found.should match /.*\/prjsync\/testA\/myfile.csproj/
   end
+
+  it "returns nil if path does not exist" do
+    finder = PrjfileFinder.new
+    found = finder.find_from './nothing/to/find.cs'
+    found.should be_nil
+  end
+
+  it "returns nil if no prj file found" do
+    finder = PrjfileFinder.new
+    found = finder.find_from './prjsync/file.cs'
+    found.should be_nil
+  end
 end