File tree Expand file tree Collapse file tree
lib/octocatalog-diff/cli/options
spec/octocatalog-diff/tests/cli/options Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Provide an optional directory to override default built-in scripts such as git checkout
4+ # and puppet version determination.
5+ # @param parser [OptionParser object] The OptionParser argument
6+ # @param options [Hash] Options hash being constructed; this is modified in this method.
7+ OctocatalogDiff ::Cli ::Options ::Option . newoption ( :override_script_path ) do
8+ has_weight 385
9+
10+ def parse ( parser , options )
11+ parser . on ( '--override-script-path DIRNAME' , 'Directory with scripts to override built-ins' ) do |dir |
12+ unless dir . start_with? ( '/' )
13+ raise ArgumentError , 'Absolute path is required for --override-script-path'
14+ end
15+
16+ unless File . directory? ( dir )
17+ raise Errno ::ENOENT , 'Invalid --override-script-path'
18+ end
19+
20+ options [ :override_script_path ] = dir
21+ end
22+ end
23+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative '../options_helper'
4+
5+ describe OctocatalogDiff ::Cli ::Options do
6+ describe '#opt_override_script_path' do
7+ context 'with relative path' do
8+ it 'should raise ArgumentError' do
9+ expect do
10+ run_optparse ( [ '--override-script-path' , '../foo/bar' ] )
11+ end . to raise_error ( ArgumentError , 'Absolute path is required for --override-script-path' )
12+ end
13+ end
14+
15+ context 'with non-existing directory' do
16+ it 'should raise Errno::ENOENT' do
17+ expect ( File ) . to receive ( :'directory?' ) . with ( '/foo/bar' ) . and_return ( false )
18+ expect do
19+ run_optparse ( [ '--override-script-path' , '/foo/bar' ] )
20+ end . to raise_error ( Errno ::ENOENT , /Invalid --override-script-path/ )
21+ end
22+ end
23+
24+ context 'with existing directory' do
25+ it 'should establish option' do
26+ expect ( File ) . to receive ( :'directory?' ) . with ( '/foo/bar' ) . and_return ( true )
27+ result = run_optparse ( [ '--override-script-path' , '/foo/bar' ] )
28+ expect ( result [ :override_script_path ] ) . to eq ( '/foo/bar' )
29+ end
30+ end
31+ end
32+ end
You can’t perform that action at this time.
0 commit comments