77 let ( :fixtures_dir ) { File . expand_path ( '../../fixtures/modules' , __dir__ ) }
88 let ( :clean_module_path ) { File . join ( fixtures_dir , 'test_module_01' ) }
99 let ( :warning_module_path ) { File . join ( fixtures_dir , 'test_module_04' ) }
10+ let ( :reserved_word_module_path ) { File . join ( fixtures_dir , 'test_module_12' ) }
1011
1112 # Runs the CLI via .start (as a user would invoke from the command line),
1213 # captures the SystemExit status, and suppresses stdout noise from the logger.
@@ -19,6 +20,8 @@ def run_cli(args)
1920 before ( :each ) do
2021 # Silence logger output to keep spec output clean.
2122 allow ( Logger ) . to receive ( :new ) . and_return ( Logger . new ( File ::NULL ) )
23+ # Prevent any real .scelint file in the working directory from affecting tests.
24+ allow ( described_class ) . to receive ( :load_defaults ) . and_return ( [ ] )
2225 end
2326
2427 describe 'invocation without an explicit subcommand' do
@@ -85,4 +88,85 @@ def run_cli(args)
8588 expect ( run_cli ( [ '--debug' , clean_module_path ] ) ) . to eq ( 0 )
8689 end
8790 end
91+
92+ describe '.scelint defaults file' do
93+ describe '.load_defaults' do
94+ before ( :each ) do
95+ allow ( described_class ) . to receive ( :load_defaults ) . and_call_original
96+ end
97+
98+ it 'returns an empty array when no .scelint file exists' do
99+ allow ( File ) . to receive ( :exist? ) . with ( described_class ::DEFAULTS_FILE ) . and_return ( false )
100+ expect ( described_class . load_defaults ) . to eq ( [ ] )
101+ end
102+
103+ it 'returns args parsed from the file' do
104+ allow ( File ) . to receive ( :exist? ) . with ( described_class ::DEFAULTS_FILE ) . and_return ( true )
105+ allow ( File ) . to receive ( :readlines ) . with ( described_class ::DEFAULTS_FILE , chomp : true )
106+ . and_return ( [ '--allow-reserved-words' , '--strict' ] )
107+ expect ( described_class . load_defaults ) . to eq ( [ '--allow-reserved-words' , '--strict' ] )
108+ end
109+
110+ it 'splits multiple args on a single line' do
111+ allow ( File ) . to receive ( :exist? ) . with ( described_class ::DEFAULTS_FILE ) . and_return ( true )
112+ allow ( File ) . to receive ( :readlines ) . with ( described_class ::DEFAULTS_FILE , chomp : true )
113+ . and_return ( [ '--allow-reserved-words --strict' ] )
114+ expect ( described_class . load_defaults ) . to eq ( [ '--allow-reserved-words' , '--strict' ] )
115+ end
116+
117+ it 'ignores blank lines' do
118+ allow ( File ) . to receive ( :exist? ) . with ( described_class ::DEFAULTS_FILE ) . and_return ( true )
119+ allow ( File ) . to receive ( :readlines ) . with ( described_class ::DEFAULTS_FILE , chomp : true )
120+ . and_return ( [ '' , '--strict' , '' ] )
121+ expect ( described_class . load_defaults ) . to eq ( [ '--strict' ] )
122+ end
123+
124+ it 'ignores comment lines' do
125+ allow ( File ) . to receive ( :exist? ) . with ( described_class ::DEFAULTS_FILE ) . and_return ( true )
126+ allow ( File ) . to receive ( :readlines ) . with ( described_class ::DEFAULTS_FILE , chomp : true )
127+ . and_return ( [ '# this is a comment' , '--strict' ] )
128+ expect ( described_class . load_defaults ) . to eq ( [ '--strict' ] )
129+ end
130+ end
131+
132+ context 'when .scelint contains --allow-reserved-words' do
133+ before ( :each ) do
134+ allow ( described_class ) . to receive ( :load_defaults ) . and_return ( [ '--allow-reserved-words' ] )
135+ end
136+
137+ it 'applies the flag without passing it on the command line' do
138+ expect ( run_cli ( [ reserved_word_module_path ] ) ) . to eq ( 0 )
139+ end
140+
141+ it 'can be overridden by --no-allow-reserved-words on the command line' do
142+ expect ( run_cli ( [ '--no-allow-reserved-words' , reserved_word_module_path ] ) ) . to eq ( 1 )
143+ end
144+ end
145+
146+ context 'when .scelint contains --strict' do
147+ before ( :each ) do
148+ allow ( described_class ) . to receive ( :load_defaults ) . and_return ( [ '--strict' ] )
149+ end
150+
151+ it 'applies --strict without passing it on the command line' do
152+ expect ( run_cli ( [ warning_module_path ] ) ) . to eq ( 1 )
153+ end
154+ end
155+ end
156+
157+ describe '--allow-reserved-words flag' do
158+ context 'when a parameter name contains a reserved word' do
159+ it 'exits 1 without --allow-reserved-words' do
160+ expect ( run_cli ( [ reserved_word_module_path ] ) ) . to eq ( 1 )
161+ end
162+
163+ it 'exits 0 with --allow-reserved-words' do
164+ expect ( run_cli ( [ '--allow-reserved-words' , reserved_word_module_path ] ) ) . to eq ( 0 )
165+ end
166+
167+ it 'exits 0 with --allow-reserved-words and --strict' do
168+ expect ( run_cli ( [ '--allow-reserved-words' , '--strict' , reserved_word_module_path ] ) ) . to eq ( 0 )
169+ end
170+ end
171+ end
88172end
0 commit comments