spec/support/helpers.rb in engineyard-0.3.3 vs spec/support/helpers.rb in engineyard-0.4.0
- old
+ new
@@ -15,11 +15,10 @@
end
NonzeroExitStatus = Class.new(UnexpectedExit)
ZeroExitStatus = Class.new(UnexpectedExit)
def ey(cmd = nil, options = {}, &block)
- require "open3"
hide_err = options.has_key?(:hide_err) ? options[:hide_err] : options[:expect_failure]
path_prepends = options[:prepend_to_path]
ey_env = {}
ey_env['DEBUG'] = options[:debug].to_s if options[:debug]
@@ -73,27 +72,15 @@
puts @err unless @err.empty? || hide_err
@out
end
- def api_scenario(scenario, remote = local_git_remote)
+ def api_scenario(scenario, remote = "user@git.host:path/to/repo.git")
response = ::RestClient.put(EY.fake_awsm + '/scenario', {"scenario" => scenario, "remote" => remote}, {})
raise "Setting scenario failed: #{response.inspect}" unless response.code == 200
end
- def local_git_remote
- remotes = []
- `git remote -v`.each_line do |line|
- parts = line.split(/\t/)
- # the remote will look like
- # "git@github.com:engineyard/engineyard.git (fetch)\n"
- # so we need to chop it up a bit
- remotes << parts[1].gsub(/\s.*$/, "") if parts[1]
- end
- remotes.first
- end
-
def read_yaml(file="ey.yml")
YAML.load_file(File.expand_path(file))
end
def write_yaml(data, file = "ey.yml")
@@ -135,7 +122,31 @@
@server = RealWeb.start_server_in_fork(config_ru)
"http://localhost:#{@server.port}"
end
end
alias_method :start_fake_awsm, :fake_awsm
+
+ def define_git_repo(name, &setup)
+ @git_repo_setup ||= {}
+ raise "Attempted to redefine git repo #{name}; don't do that!" if @git_repo_setup.has_key?(name)
+ @git_repo_setup[name] = setup
+ end
+
+ def git_repo_dir(name)
+ @git_repo_dir_cache ||= {}
+ return @git_repo_dir_cache[name] if @git_repo_dir_cache.has_key?(name)
+ raise ArgumentError, "No definition for git repo #{name}" unless @git_repo_setup[name]
+
+ git_dir = Pathname.new("/tmp/engineyard_test_repo_#{Time.now.tv_sec}_#{Time.now.tv_usec}_#{$$}")
+ git_dir.mkdir
+ Dir.chdir(git_dir) do
+ system("git init -q")
+ system('git config user.email ey@spec.test')
+ system('git config user.name "EY Specs"')
+ system("git remote add testremote user@git.host:path/to/repo.git")
+ @git_repo_setup[name].call(git_dir)
+ end
+ @git_repo_dir_cache[name] = git_dir
+ end
+
end
end