|
143 | 143 |
|
144 | 144 | context "with environment variables" do
|
145 | 145 | around do |example|
|
146 |
| - original_env = ENV.to_h |
| 146 | + original_env = ENV.to_h.dup # Use .dup to ensure we have a copy |
147 | 147 | example.run
|
| 148 | + ensure # Ensure ENV is restored even if the example fails |
148 | 149 | ENV.replace(original_env)
|
149 | 150 | end
|
150 | 151 |
|
|
171 | 172 | expect(config[:log_level]).to eq("warn")
|
172 | 173 | expect(config[:environment]).to eq("production") # should remain default
|
173 | 174 | expect(config[:production]).to be true
|
| 175 | + # Ensure other ENV vars are not set from previous examples in this context |
| 176 | + expect(ENV["HOOKS_ENVIRONMENT"]).to be_nil |
| 177 | + expect(ENV["HOOKS_REQUEST_LIMIT"]).to be_nil |
174 | 178 | end
|
175 | 179 |
|
176 | 180 | it "processes empty environment variables (empty strings are truthy)" do
|
|
185 | 189 | ENV["HOOKS_USE_CATCHALL_ROUTE"] = "true"
|
186 | 190 | ENV["HOOKS_SYMBOLIZE_PAYLOAD"] = "1"
|
187 | 191 | ENV["HOOKS_NORMALIZE_HEADERS"] = "yes"
|
| 192 | + # Add a non-boolean var to ensure it's not misinterpreted |
| 193 | + ENV["HOOKS_SOME_STRING_VAR"] = "test_value" |
| 194 | + |
188 | 195 |
|
189 | 196 | config = described_class.load
|
190 | 197 |
|
191 | 198 | expect(config[:use_catchall_route]).to be true
|
192 | 199 | expect(config[:symbolize_payload]).to be true
|
193 | 200 | expect(config[:normalize_headers]).to be true
|
| 201 | + expect(config[:some_string_var]).to eq("test_value") # Check the string var |
194 | 202 | end
|
195 | 203 | end
|
196 | 204 |
|
197 | 205 | context "with auth plugin directory configuration" do
|
| 206 | + around do |example| |
| 207 | + original_env = ENV.to_h.dup |
| 208 | + example.run |
| 209 | + ensure |
| 210 | + ENV.replace(original_env) |
| 211 | + end |
| 212 | + |
198 | 213 | it "includes auth_plugin_dir in default configuration" do
|
199 | 214 | config = described_class.load
|
200 | 215 |
|
|
215 | 230 | config = described_class.load
|
216 | 231 |
|
217 | 232 | expect(config[:auth_plugin_dir]).to eq("/opt/auth/plugins")
|
218 |
| - ensure |
219 |
| - ENV.delete("HOOKS_AUTH_PLUGIN_DIR") |
| 233 | + # No ensure block needed here as the around hook handles cleanup |
220 | 234 | end
|
221 | 235 | end
|
222 | 236 |
|
|
0 commit comments