require 'spec_helper' require 'pathname' require 'fileutils' describe Evrone::CI::Worker::LocalScript do let(:before_script) { "echo before_script" } let(:script) { "echo script" } let(:app) { ->(_) { 0 } } let(:job) { create :job, script: script, before_script: before_script } let(:path_prefix) { Pathname.new "/tmp/.ci" } let(:work_dir) { path_prefix.join("work") } let(:tmp_dir) { path_prefix.join("tmp") } let(:env) { OpenStruct.new job: job, work_dir: work_dir, tmp_dir: tmp_dir } let(:mid) { described_class.new app } subject { mid.call env } after do FileUtils.rm_rf path_prefix end before do FileUtils.mkdir_p work_dir FileUtils.mkdir_p tmp_dir end it { should eq 0 } it "should capture output" do subject job.release expect(last_job_log_message.log).to be_include("before_script\nscript\n") end context "when script failed" do let(:script) { 'false' } it { should satisfy { |n| [1,127].include?(n) } } end context "when before_script failed" do let(:before_script) { 'false' } it { should satisfy { |n| [-1,-127].include?(n) } } end end