Class: RSpec::Terraspace::Ts

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/rspec/terraspace/ts.rb

Constant Summary collapse

CLI =
::Terraspace::CLI

Instance Method Summary collapse

Instance Method Details

#build_test_harness(options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/rspec/terraspace/ts.rb', line 9

def build_test_harness(options={})
  project = Project.new(options)
  root = project.create
  Terraspace.root = root # switch root to the generated test harness
end

#down(args) ⇒ Object



22
23
24
# File 'lib/rspec/terraspace/ts.rb', line 22

def down(args)
  run("down #{args} -y")
end

#out_pathObject



46
47
48
# File 'lib/rspec/terraspace/ts.rb', line 46

def out_path
  "#{Terraspace.tmp_root}/rspec/output.json"
end

#output(mod, name) ⇒ Object



38
39
40
# File 'lib/rspec/terraspace/ts.rb', line 38

def output(mod, name)
  outputs.dig(name, "value")
end

#outputsObject



42
43
44
# File 'lib/rspec/terraspace/ts.rb', line 42

def outputs
  JSON.load(IO.read(out_path))
end

#run(command) ⇒ Object



26
27
28
29
30
# File 'lib/rspec/terraspace/ts.rb', line 26

def run(command)
  puts "=> terraspace #{command}".color(:green)
  args = command.split(' ')
  CLI.start(args)
end

#save_outputObject

Note: a terraspace.down will remove the output.json since it does a clean



33
34
35
36
# File 'lib/rspec/terraspace/ts.rb', line 33

def save_output
  FileUtils.mkdir_p(File.dirname(out_path))
  run("output #{@mod.name} --format json --out #{out_path}")
end

#up(args) ⇒ Object



15
16
17
18
19
20
# File 'lib/rspec/terraspace/ts.rb', line 15

def up(args)
  run("up #{args} -y")
  mod = args.split(' ').first
  @mod = ::Terraspace::Mod.new(mod)
  save_output
end