require 'spec_helper' require 'vx/common/spawn' require 'fileutils' describe Vx::Router::ScriptBuilder::Prepare do let(:path) { '/tmp/.test' } let(:app) { ->(_) { _ } } let(:build) { create :build } let(:env) { OpenStruct.new build: build, init: [] } let(:mid) { described_class.new app } subject { mid.call env } before do FileUtils.rm_rf path FileUtils.mkdir_p path end after { FileUtils.rm_rf path } it { should eq env } its(:init) { should_not be_empty } context "run compiled script" do include Vx::Common::Spawn let(:script) { "set -e\nset -x\n" + env.init.join("\n") } before { mid.call env } it "should be success" do code = spawn script, chdir: path do |out| puts " ===> #{out}" end expect(code).to eq 0 expect(File).to be_readable("#{path}/data/evrone/test-repo/git_ssh") expect(File).to be_readable("#{path}/data/evrone/test-repo/key") expect(File).to be_directory("#{path}/code/evrone/test-repo/.git") expect(File).to be_readable("#{path}/code/evrone/test-repo/Rakefile") end end end