|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../options_helper' |
| 4 | + |
| 5 | +describe OctocatalogDiff::Cli::Options do |
| 6 | + describe '#opt_save_catalog' do |
| 7 | + it 'should raise error if catalog parent directory does not exist' do |
| 8 | + args = [ |
| 9 | + '--to-save-catalog', |
| 10 | + OctocatalogDiff::Spec.fixture_path('non/exists/catalog.json') |
| 11 | + ] |
| 12 | + expect { run_optparse(args) }.to raise_error(Errno::ENOENT, /parent directory does not exist/) |
| 13 | + end |
| 14 | + |
| 15 | + it 'should raise error if catalog exists but is not a file' do |
| 16 | + args = [ |
| 17 | + '--to-save-catalog', |
| 18 | + OctocatalogDiff::Spec.fixture_path('repos/default') |
| 19 | + ] |
| 20 | + expect { run_optparse(args) }.to raise_error(ArgumentError, /Cannot overwrite/) |
| 21 | + end |
| 22 | + |
| 23 | + it 'should not raise error if catalog file already exists' do |
| 24 | + args = [ |
| 25 | + '--to-save-catalog', |
| 26 | + OctocatalogDiff::Spec.fixture_path('catalogs/catalog-1.json') |
| 27 | + ] |
| 28 | + result = run_optparse(args) |
| 29 | + expect(result[:to_save_catalog]).to eq(OctocatalogDiff::Spec.fixture_path('catalogs/catalog-1.json')) |
| 30 | + end |
| 31 | + |
| 32 | + it 'should not raise error if catalog file does not exist' do |
| 33 | + args = [ |
| 34 | + '--to-save-catalog', |
| 35 | + OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json') |
| 36 | + ] |
| 37 | + result = run_optparse(args) |
| 38 | + expect(result[:to_save_catalog]).to eq(OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json')) |
| 39 | + end |
| 40 | + |
| 41 | + it 'should raise error if --to-save-catalog == --from-save-catalog' do |
| 42 | + args = [ |
| 43 | + '--to-save-catalog', |
| 44 | + OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json'), |
| 45 | + '--from-save-catalog', |
| 46 | + OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json') |
| 47 | + ] |
| 48 | + expect { run_optparse(args) }.to raise_error(ArgumentError, /Cannot use the same file for/) |
| 49 | + end |
| 50 | + |
| 51 | + it 'should not raise error if --to-save-catalog and --from-save-catalog are both nil' do |
| 52 | + args = [] |
| 53 | + result = run_optparse(args) |
| 54 | + expect(result[:to_save_catalog]).to be_nil |
| 55 | + expect(result[:from_save_catalog]).to be_nil |
| 56 | + end |
| 57 | + |
| 58 | + it 'should set option correctly' do |
| 59 | + args = [ |
| 60 | + '--to-save-catalog', |
| 61 | + OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json'), |
| 62 | + '--from-save-catalog', |
| 63 | + OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-2.json') |
| 64 | + ] |
| 65 | + result = run_optparse(args) |
| 66 | + expect(result[:to_save_catalog]).to eq(OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-1.json')) |
| 67 | + expect(result[:from_save_catalog]).to eq(OctocatalogDiff::Spec.fixture_path('catalogs/brand-new-catalog-2.json')) |
| 68 | + end |
| 69 | + end |
| 70 | +end |
0 commit comments