@@ -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 } ,
@@ -286,19 +308,19 @@ def yaml_to_path(yaml)
286308 end
287309
288310 context "when warning when a value isn't a string" do
289- let ( :config ) { { "string key " => :SYMBOL_VALUE } }
311+ let ( :config ) { { "STRING_KEY " => :SYMBOL_VALUE } }
290312
291313 include_examples "correct warning with and without silence override"
292314 end
293315
294316 it "allows nil values" do
295- allow ( application ) . to receive ( :configuration ) . and_return ( { "foo " => nil } )
317+ allow ( application ) . to receive ( :configuration ) . and_return ( { "FOO " => nil } )
296318
297319 expect {
298320 application . load
299321 } . not_to (
300322 change {
301- ::ENV [ "foo " ]
323+ ::ENV [ "FOO " ]
302324 }
303325 )
304326 end
0 commit comments