homebrew-cask-versions/test/support/fake_system_command.rb
phinze 171456dc98 support for install/uninstall
accepts a single argument, which is a relative path to a pkg
inside the extracted Cask; homebrew-cask will attempt to install this
pkg after the Cask is extracted via `installer`

because of the many different ways uninstallers work, this
has several features:

 - `:script`: a script in the Cask which serves as an uninstaller (e.g.
   Vagrant, VirtualBox), uses `:args`, and `:input` keys to interact
   with said script
 - `:pkgutil`: a regexp which captures all package_ids installed by this
   cask; homebrew-cask will list all files installed under these ids and
   remove them
 - `:launchctl`: a list of bundle_ids for services that should be
   removed by homebrew-cask
 - `:files`: a fallback list of files to manually remove; helps when
   uninstallers miss something

refs #661
2013-07-21 22:01:38 -05:00

46 lines
929 B
Ruby

class Cask::FakeSystemCommand
def self.fake_response_for(command, response='')
@responses ||= {}
@responses[command] = response
end
def self.system_calls
@system_calls
end
def self.init
@responses = {}
end
def self.clear
@responses = {}
@system_calls = Hash.new(0)
end
def self.run(command, options={})
command = Cask::SystemCommand._process_options(command, options)
@responses ||= {}
@system_calls ||= Hash.new(0)
unless @responses.key?(command)
fail("no response faked for #{command.inspect}, faked responses are: #{@responses.inspect}")
end
@system_calls[command] += 1
@responses[command].split("\n")
end
end
module FakeSystemCommandHooks
def before_setup
Cask::FakeSystemCommand.init
super
end
def after_teardown
super
Cask::FakeSystemCommand.clear
end
end
class MiniTest::Spec
include FakeSystemCommandHooks
end