|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../spec_helper' |
| 4 | +require OctocatalogDiff::Spec.require_path('/util/scriptrunner') |
| 5 | + |
| 6 | +describe OctocatalogDiff::Util::ScriptRunner do |
| 7 | + describe '#initialize' do |
| 8 | + before(:each) do |
| 9 | + @logger, @logger_str = OctocatalogDiff::Spec.setup_logger |
| 10 | + end |
| 11 | + |
| 12 | + it 'should raise error when script cannot be found' do |
| 13 | + opts = { |
| 14 | + default_script: 'git-extract/THIS-DOES-NOT-EXIST', |
| 15 | + working_dir: File.dirname(__FILE__), |
| 16 | + logger: @logger |
| 17 | + } |
| 18 | + expect { described_class.new(opts) }.to raise_error(Errno::ENOENT) |
| 19 | + end |
| 20 | + |
| 21 | + it 'should raise error when working directory cannot be found' do |
| 22 | + opts = { |
| 23 | + default_script: 'git-extract/git-extract.sh', |
| 24 | + working_dir: File.join(File.dirname(__FILE__), 'THIS-DOES-NOT-EXIST'), |
| 25 | + logger: @logger |
| 26 | + } |
| 27 | + expect { described_class.new(opts) }.to raise_error(Errno::ENOENT) |
| 28 | + end |
| 29 | + |
| 30 | + it 'should use override script when it is found' do |
| 31 | + opts = { |
| 32 | + default_script: 'asdflkjasf/scriptrunner_spec.rb', |
| 33 | + working_dir: File.join(File.dirname(__FILE__)), |
| 34 | + override_script_path: File.join(File.dirname(__FILE__)), |
| 35 | + logger: @logger |
| 36 | + } |
| 37 | + obj = described_class.new(opts) |
| 38 | + expect(obj.script).to eq(__FILE__) |
| 39 | + end |
| 40 | + |
| 41 | + it 'should use default script when override is not found' do |
| 42 | + opts = { |
| 43 | + default_script: 'git-extract/git-extract.sh', |
| 44 | + working_dir: File.join(File.dirname(__FILE__)), |
| 45 | + override_script_path: File.join(File.dirname(__FILE__)), |
| 46 | + logger: @logger |
| 47 | + } |
| 48 | + obj = described_class.new(opts) |
| 49 | + answer = File.expand_path('../../../../scripts/git-extract/git-extract.sh', File.dirname(__FILE__)) |
| 50 | + expect(obj.script).to eq(answer) |
| 51 | + end |
| 52 | + |
| 53 | + it 'should use default script when override is not provided' do |
| 54 | + opts = { |
| 55 | + default_script: 'git-extract/git-extract.sh', |
| 56 | + working_dir: File.join(File.dirname(__FILE__)), |
| 57 | + logger: @logger |
| 58 | + } |
| 59 | + obj = described_class.new(opts) |
| 60 | + answer = File.expand_path('../../../../scripts/git-extract/git-extract.sh', File.dirname(__FILE__)) |
| 61 | + expect(obj.script).to eq(answer) |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments