Skip to content

Commit

Permalink
Refactor test setup of gem
Browse files Browse the repository at this point in the history
  • Loading branch information
tawan committed Nov 20, 2017
1 parent 52c645f commit 862cbc1
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -105,20 +109,24 @@ 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)
end
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
Expand Down

0 comments on commit 862cbc1

Please sign in to comment.