Module: Tomo::Testing::Local
- Included in:
- CLITester
- Defined in:
- lib/tomo/testing/local.rb
Class Method Summary collapse
- .capture(*command, raise_on_error: true) ⇒ Object
- .in_temp_dir(token = nil) ⇒ Object
- .with_tomo_gemfile ⇒ Object
Instance Method Summary collapse
- #capture(*command, raise_on_error: true) ⇒ Object
- #in_temp_dir(token = nil) ⇒ Object
- #with_tomo_gemfile ⇒ Object
Class Method Details
.capture(*command, raise_on_error: true) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tomo/testing/local.rb', line 41 def capture(*command, raise_on_error: true) command_str = command.join(" ") progress(command_str) do output, status = Open3.capture2e(*command) raise "Command failed: #{command_str}\n#{output}" if raise_on_error && !status.success? output end end |
.in_temp_dir(token = nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/tomo/testing/local.rb', line 34 def in_temp_dir(token=nil, &) token ||= SecureRandom.hex(8) dir = File.join(Dir.tmpdir, "tomo_test_#{token}") FileUtils.mkdir_p(dir) Dir.chdir(dir, &) end |
.with_tomo_gemfile ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/tomo/testing/local.rb', line 26 def with_tomo_gemfile Bundler.with_original_env do gemfile = File.("../../../Gemfile", __dir__) ENV["BUNDLE_GEMFILE"] = gemfile yield end end |
Instance Method Details
#capture(*command, raise_on_error: true) ⇒ Object
21 22 23 |
# File 'lib/tomo/testing/local.rb', line 21 def capture(*command, raise_on_error: true) Local.capture(*command, raise_on_error:) end |
#in_temp_dir(token = nil) ⇒ Object
17 18 19 |
# File 'lib/tomo/testing/local.rb', line 17 def in_temp_dir(token=nil, &) Local.in_temp_dir(token, &) end |
#with_tomo_gemfile ⇒ Object
13 14 15 |
# File 'lib/tomo/testing/local.rb', line 13 def with_tomo_gemfile(&) Local.with_tomo_gemfile(&) end |