Class: Spoom::TestHelpers::Project
- Inherits:
-
Object
- Object
- Spoom::TestHelpers::Project
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/test_helpers/project.rb
Overview
A simple project abstraction for testing purposes
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #bundle_exec(cmd, *args) ⇒ Object
- #bundle_install ⇒ Object
- #commit(message = "message", date: Time.now.utc) ⇒ Object
- #create_and_checkout_branch(name) ⇒ Object
- #current_branch ⇒ Object
- #destroy ⇒ Object
- #files ⇒ Object
- #gemfile(content) ⇒ Object
- #git_init(branch: "main") ⇒ Object
-
#initialize(path) ⇒ Project
constructor
A new instance of Project.
- #remove(rel_path) ⇒ Object
- #sorbet_config(content) ⇒ Object
- #write(rel_path, content = "") ⇒ Object
Constructor Details
#initialize(path) ⇒ Project
Returns a new instance of Project.
22 23 24 25 26 |
# File 'lib/spoom/test_helpers/project.rb', line 22 def initialize(path) @path = path FileUtils.rm_rf(@path) FileUtils.mkdir_p(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/spoom/test_helpers/project.rb', line 18 def path @path end |
Instance Method Details
#bundle_exec(cmd, *args) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/spoom/test_helpers/project.rb', line 90 def bundle_exec(cmd, *args) opts = {} opts[:chdir] = path out, err, status = Open3.capture3(["bundle", "exec", cmd, *args].join(' '), opts) [out, err, T.must(status.success?)] end |
#bundle_install ⇒ Object
81 82 83 84 85 86 |
# File 'lib/spoom/test_helpers/project.rb', line 81 def bundle_install opts = {} opts[:chdir] = path out, err, status = Open3.capture3("bundle", "install", opts) [out, err, T.must(status.success?)] end |
#commit(message = "message", date: Time.now.utc) ⇒ Object
74 75 76 77 |
# File 'lib/spoom/test_helpers/project.rb', line 74 def commit( = "message", date: Time.now.utc) Spoom::Git.exec("git add --all", path: path) Spoom::Git.exec("GIT_COMMITTER_DATE=\"#{date}\" git commit -m '#{}' --date '#{date}'", path: path) end |
#create_and_checkout_branch(name) ⇒ Object
104 105 106 |
# File 'lib/spoom/test_helpers/project.rb', line 104 def create_and_checkout_branch(name) Spoom::Git.exec("git checkout -b #{name}", path: path) end |
#current_branch ⇒ Object
109 110 111 |
# File 'lib/spoom/test_helpers/project.rb', line 109 def current_branch Spoom::Git.current_branch(path: path) end |
#destroy ⇒ Object
99 100 101 |
# File 'lib/spoom/test_helpers/project.rb', line 99 def destroy FileUtils.rm_rf(path) end |
#files ⇒ Object
58 59 60 |
# File 'lib/spoom/test_helpers/project.rb', line 58 def files Dir.glob("#{@path}/**/*").sort end |
#gemfile(content) ⇒ Object
32 33 34 |
# File 'lib/spoom/test_helpers/project.rb', line 32 def gemfile(content) write("Gemfile", content) end |
#git_init(branch: "main") ⇒ Object
66 67 68 69 70 |
# File 'lib/spoom/test_helpers/project.rb', line 66 def git_init(branch: "main") Spoom::Git.exec("git init -q -b #{branch}", path: path) Spoom::Git.exec("git config user.name 'spoom-tests'", path: path) Spoom::Git.exec("git config user.email '[email protected]'", path: path) end |
#remove(rel_path) ⇒ Object
52 53 54 |
# File 'lib/spoom/test_helpers/project.rb', line 52 def remove(rel_path) FileUtils.rm_rf(absolute_path(rel_path)) end |
#sorbet_config(content) ⇒ Object
38 39 40 |
# File 'lib/spoom/test_helpers/project.rb', line 38 def sorbet_config(content) write("sorbet/config", content) end |
#write(rel_path, content = "") ⇒ Object
44 45 46 47 48 |
# File 'lib/spoom/test_helpers/project.rb', line 44 def write(rel_path, content = "") path = absolute_path(rel_path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, content) end |