Permalink
Browse files

Only delete the old file on updating when the installation of the new…

… one is a success
  • Loading branch information...
1 parent 1faf606 commit e9441a63092341446d132e3abb552c666a319d0d @cypher cypher committed May 29, 2008
Showing with 5 additions and 4 deletions.
  1. +4 −3 lib/thor/runner.rb
  2. +1 −1 spec/thor_runner_spec.rb
View
@@ -33,7 +33,7 @@ def install(name, opts = {})
print "Do you wish to continue [y/N]? "
response = Readline.readline
- return unless response =~ /^\s*y/i
+ return false unless response =~ /^\s*y/i
constants = Thor::Util.constants_in_contents(contents)
@@ -67,6 +67,8 @@ def install(name, opts = {})
File.open(File.join(thor_root, yaml[as][:filename] + ".thor"), "w") do |file|
file.puts contents
end
+
+ true # Indicate sucess
end
desc "uninstall NAME", "uninstall a named Thor module"
@@ -91,8 +93,7 @@ def update(name)
puts "Updating `#{name}' from #{yaml[name][:location]}"
old_filename = yaml[name][:filename] + ".thor"
- install(yaml[name][:location], "as" => name)
- File.delete(File.join(thor_root, old_filename))
+ File.delete(File.join(thor_root, old_filename)) if install(yaml[name][:location], "as" => name)
end
desc "installed", "list the installed Thor modules and tasks (--internal means list the built-in tasks as well)"
View
@@ -138,7 +138,7 @@ class ThorTask2 < Thor
describe " update" do
it "updates existing thor files" do
- @runner.should_receive(:install).with(@original_yaml["random"][:location], {"as" => "random"})
+ @runner.should_receive(:install).with(@original_yaml["random"][:location], {"as" => "random"}).and_return(true)
File.should_receive(:delete).with(File.join(ENV["HOME"], ".thor", @original_yaml["random"][:filename] + ".thor"))
silence(:stdout) { @runner.update("random") }

0 comments on commit e9441a6

Please sign in to comment.