summaryrefslogtreecommitdiff
path: root/spec/support/project.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-09-14 16:40:00 -0600
committermo khan <mo.khan@gmail.com>2020-09-14 16:40:00 -0600
commit0dc0c0cec97cbdea04e278143e4711cfa0d3bd03 (patch)
treea650f1421d0e57b13024df1fb4efe5aa76b96dfb /spec/support/project.rb
parentcea7d78e2d7f1a8f98880819b8589925b5daef1a (diff)
test: add spec to run gemnasium-maven scanner
Diffstat (limited to 'spec/support/project.rb')
-rw-r--r--spec/support/project.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/support/project.rb b/spec/support/project.rb
new file mode 100644
index 0000000..a90dfd6
--- /dev/null
+++ b/spec/support/project.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+require 'securerandom'
+
+class Project
+ attr_reader :path
+
+ def initialize(path = Pathname.pwd.join('tmp').join(SecureRandom.uuid))
+ FileUtils.mkdir_p(path)
+ @path = Pathname(path)
+ end
+
+ def mount(dir:)
+ FileUtils.cp_r("#{dir}/.", path)
+ end
+
+ def chdir
+ Dir.chdir path do
+ yield
+ end
+ end
+
+ def clone(repo, branch: 'master')
+ if branch.match?(/\b[0-9a-f]{5,40}\b/)
+ execute({}, 'git', 'clone', '--quiet', repo, path.to_s)
+ chdir do
+ execute({}, 'git', 'checkout', branch)
+ end
+ else
+ execute({}, 'git', 'clone', '--quiet', '--depth=1', '--single-branch', '--branch', branch, repo, path.to_s)
+ end
+ end
+
+ def execute(env = {}, *args)
+ Bundler.with_unbundled_env do
+ system(env, *args, exception: true)
+ end
+ end
+
+ def cleanup
+ FileUtils.rm_rf(path) if path.exist?
+ end
+end