spec/spec_helper.rb in rocketstarter-0.0.3 vs spec/spec_helper.rb in rocketstarter-0.1.0

- old
+ new

@@ -6,5 +6,153 @@ require 'spec' end $:.unshift(File.dirname(__FILE__) + '/../lib') require 'rocketstarter' + + +def move_to_sandbox + sandbox_path = test_dir + unless FileTest::directory?(sandbox_path) + puts 'This spec needs a sandbox directory at ' + sandbox_path + puts 'If you want to countinue, please make it first!' + return false + end + Dir::chdir(sandbox_path) + if sandbox_path == Dir::pwd + return true + else + return false + end +end + +def clean_up_sandbox + `rm -rf ./gitproj` + return false unless 0 == $? + `rm -rf ./svnproj` + return false unless 0 == $? + `rm -rf ./setting` + return false unless 0 == $? + return true +end + +def test_dir + ENV["HOME"] + "/sandbox/rocketstarter" +end + +def path_of_config_file + test_dir + "/setting/rocketstarter" +end + +def path_of_plugin_list_file + test_dir + "/setting/pluginlist" +end + +def path_of_program + "/opt/local/bin/rocketstarter" +end + +def setup_config_directory + Dir.mkdir("setting") +end + +def build_option_string(options) + option_string = "" + options.each_pair do |key, value| + if "true" == value or "false" == value + option_string << " --#{key}" + else + option_string << " --#{key}=#{value}" + end + end + option_string +end + +def setup_config_file(options = nil, how_many = 2) + option_string = "" + if options + option_string = build_option_string(options) + end + commandline = "|#{path_of_program} --init --conf=#{path_of_config_file} --listpath=#{path_of_plugin_list_file} #{option_string}" + open(commandline, "r+") do |rs| + how_many.times do + rs.puts "y" + end +# rs.puts "y" # ask to create for config +# rs.puts "y" # ask to over write for config +# rs.puts "y" # ask to create for plugin list +# rs.puts "y" # ask to over write for plugin list + end + return true +end + +=begin +/Users/maimuzo/sandbox/rocketstarter/setting% rocketstarter --check +current variables +scmtype:svn +skip_plugins:false +emulate:false +log_file:/Users/maimuzo/rocket_starter.log +check:true +scmuri: +verbose:true +pluginlist_path:/Users/maimuzo/.rocket_starter_pluginlist +external:false +scmpassword:mogemoge +ignoredatabase:true +logging:true +createdb:true +rapt:true +skip_commit_for_plugins:false +rocket_starter_conf_path:/Users/maimuzo/.rocket_starter +project:--check +database:mysql +sudo:false +skip_netbeans:false +dbpassword: +init:false + +=end + +def parse_setting + parsed_param = {} + result = `#{path_of_program} --check --conf=#{path_of_config_file}` + return false unless 0 == $? + result.each do |line| + temp = line.scan(/^(.+):(.+)$/) + parsed_param[temp[0][0]] = temp[0][1] if temp.size > 0 + end + parsed_param +end + +class Hash + def includes_hash?(target) + result = target.reject do |key, value| + !self[key].nil? and value == self[key] + end + result.empty? + end +end + +def create_repos_with(options) + project_name = options.delete("project") + option_string = build_option_string(options) + result = `#{path_of_program} #{project_name} --conf=#{path_of_config_file} #{option_string}` + return false unless 0 == $? + result +end + +def clean_up_at_svn_repository(secret) + begin + uri = secret["scmuri"] + password = secret["scmpassword"] + `svn delete #{uri}/trunk -m "clean up trunk for test" --password #{password}` + raise "command error" unless 0 == $? + `svn delete #{uri}/branches -m "clean up branches for test" --password #{password}` + raise "command error" unless 0 == $? + `svn delete #{uri}/tags -m "clean up tags for test" --password #{password}` + raise "command error" unless 0 == $? + rescue + puts "This message was showed when the subversion repository is empty. In this case is no probrem." + return false + end +end