lib/rspec/terraspace/ts.rb in rspec-terraspace-0.0.0 vs lib/rspec/terraspace/ts.rb in rspec-terraspace-0.1.0

- old
+ new

@@ -7,38 +7,42 @@ CLI = ::Terraspace::CLI def build_test_harness(options={}) puts "Building test harness..." project = Project.new(options) - @ts_root = project.create - ENV['TS_ROOT'] = @ts_root # switch root to the generated test harness + root = project.create + Terraspace.root = root # switch root to the generated test harness end def up(args) run("up #{args} -y") + mod = args.split(' ').first + @mod = ::Terraspace::Mod.new(mod) + save_output end def down(args) run("down #{args} -y") end def run(command) + puts "=> terraspace #{command}".color(:green) args = command.split(' ') CLI.start(args) end - def save_output(mod) - run("output #{mod} --json --save-to #{saved_output_path}") + # Note: a terraspace.down will remove the output.json since it does a clean + def save_output + FileUtils.mkdir_p(File.dirname(out_path)) + run("output #{@mod.name} --format json --out #{out_path}") end - memoize :save_output def output(mod, name) - save_output(mod) - data = JSON.load(IO.read(saved_output_path)) + data = JSON.load(IO.read(out_path)) data.dig(name, "value") end - def saved_output_path - "#{@ts_root}/output.json" + def out_path + "#{Terraspace.tmp_root}/rspec/output.json" end end end