@@ -200,44 +200,66 @@ def yaml_to_path(yaml)
200200 let! ( :application ) { described_class . new }
201201
202202 before do
203- allow ( application ) . to receive ( :configuration ) . and_return ( { "foo" => "bar" } )
203+ # Update to use uppercase keys in the default configuration
204+ allow ( application ) . to receive ( :configuration ) . and_return ( { "FOO" => "bar" } )
204205 end
205206
206207 it "merges values into ENV" do
207208 expect {
208209 application . load
209210 } . to change {
210- ::ENV [ "foo " ]
211+ ::ENV [ "FOO " ]
211212 } . from ( nil ) . to ( "bar" )
212213 end
213214
214215 it "skips keys (and warns) that have already been set externally" do
215- ::ENV [ "foo " ] = "baz"
216+ ::ENV [ "FOO " ] = "baz"
216217
217218 expect ( application )
218- . to receive ( :puts ) . with ( 'INFO: Skipping key "foo ". Already set in ENV.' )
219+ . to receive ( :puts ) . with ( 'INFO: Skipping key "FOO ". Already set in ENV.' )
219220
220221 expect {
221222 application . load
222223 } . not_to (
223224 change {
224- ::ENV [ "foo " ]
225+ ::ENV [ "FOO " ]
225226 }
226227 )
227228 end
228229
229230 it "sets keys that have already been set internally" do
230231 application . load
231232
232- allow ( application ) . to receive ( :configuration ) . and_return ( { "foo " => "baz" } )
233+ allow ( application ) . to receive ( :configuration ) . and_return ( { "FOO " => "baz" } )
233234
234235 expect {
235236 application . load
236237 } . to change {
237- ::ENV [ "foo " ]
238+ ::ENV [ "FOO " ]
238239 } . from ( "bar" ) . to ( "baz" )
239240 end
240241
242+ it "raises an error for keys that are not all uppercase" do
243+ allow ( application ) . to receive ( :configuration ) . and_return ( { "foo" => "bar" ,
244+ "FOO_BAR" => "baz" } )
245+
246+ expect {
247+ application . load
248+ } . to raise_error ( Figjam ::InvalidKeyNameError ,
249+ 'Environment variable names must be uppercase: "foo"' )
250+ end
251+
252+ it "accepts keys that are all uppercase" do
253+ allow ( application ) . to receive ( :configuration ) . and_return ( { "FOO" => "bar" ,
254+ "BAR_BAZ" => "qux" } )
255+
256+ expect {
257+ application . load
258+ } . to change {
259+ [ ::ENV [ "FOO" ] , ::ENV [ "BAR_BAZ" ] ]
260+ } . from ( [ nil , nil ] ) . to ( %w[ bar qux ] )
261+ end
262+
241263 shared_examples "correct warning with and without silence override" do
242264 [
243265 { FIGARO_SILENCE_STRING_WARNINGS : true } ,
@@ -280,25 +302,27 @@ def yaml_to_path(yaml)
280302 end
281303
282304 context "when warning when a key isn't a string" do
305+ # Use uppercase symbol keys to avoid validation failures
283306 let ( :config ) { { SYMBOL_KEY : "string value" } }
284307
285308 include_examples "correct warning with and without silence override"
286309 end
287310
288311 context "when warning when a value isn't a string" do
289- let ( :config ) { { "string key" => :SYMBOL_VALUE } }
312+ # Update to use uppercase string key
313+ let ( :config ) { { "STRING_KEY" => :SYMBOL_VALUE } }
290314
291315 include_examples "correct warning with and without silence override"
292316 end
293317
294318 it "allows nil values" do
295- allow ( application ) . to receive ( :configuration ) . and_return ( { "foo " => nil } )
319+ allow ( application ) . to receive ( :configuration ) . and_return ( { "FOO " => nil } )
296320
297321 expect {
298322 application . load
299323 } . not_to (
300324 change {
301- ::ENV [ "foo " ]
325+ ::ENV [ "FOO " ]
302326 }
303327 )
304328 end
0 commit comments