diff --git a/spec/helpers.rb b/spec/helpers.rb index e86331a..7577419 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -38,13 +38,9 @@ def initialize(version = "4.2") end def deploy - build_gem - begin - unpack_gem_into_vendor_dir + use_gem do deploy_to_environment(WEB_ENV_NAME) deploy_to_environment(WORKER_ENV_NAME) - ensure - remove_gem end end @@ -80,8 +76,10 @@ def create_random_string(random_string) end def run_in_rails_app_root_dir(&block) - Dir.chdir("#{root_dir}/spec/integration/rails-app-#{@version}") do - yield + use_gem do + Dir.chdir("#{root_dir}/spec/integration/rails-app-#{@version}") do + yield + end end end @@ -95,6 +93,12 @@ def deploy_to_environment(env) end end + def use_gem(&block) + build_gem + unpack_gem_into_vendor_dir(&block) + remove_gem + end + def build_gem sh( "gem build active-elastic-job.gemspec", @@ -105,7 +109,7 @@ def remove_gem sh("rm -rf #{gem_package_name}.gem", "Could not remove gem") end - def unpack_gem_into_vendor_dir + def unpack_gem_into_vendor_dir(&block) target_dir = "#{root_dir}/spec/integration/rails-app-#{@version}/vendor/gems" unless File.directory?(target_dir) FileUtils.mkdir_p(target_dir) @@ -113,12 +117,16 @@ def unpack_gem_into_vendor_dir sh( "gem unpack #{gem_package_name}.gem --target #{target_dir}", "Could not unpack gem") - sh( - "rm -rf #{target_dir}/active_elastic_job-current", - "Could not move gem") sh( "mv #{target_dir}/#{gem_package_name} #{target_dir}/active_elastic_job-current", "Could not move gem") + begin + yield + ensure + sh( + "rm -rf #{target_dir}/active_elastic_job-current", + "Could not remove gem") + end end def gem_package_name