|
27 | 27 |
|
28 | 28 | let(:environment_variable) { described_class.new(**args) }
|
29 | 29 |
|
| 30 | + around do |example| |
| 31 | + Nvar.env.then do |old_env| |
| 32 | + Nvar.env = ActiveSupport::StringInquirer.new(nvar_env.to_s) |
| 33 | + example.run |
| 34 | + ensure |
| 35 | + Nvar.env = old_env |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + let(:nvar_env) { :development } |
| 40 | + |
30 | 41 | describe "#initialize" do
|
31 | 42 | subject(:initializer) { environment_variable }
|
32 | 43 |
|
|
112 | 123 | context "when passthrough is false and a default value is provided" do
|
113 | 124 | let(:args) { base_args.merge(passthrough: false, default_value: "default_value") }
|
114 | 125 |
|
115 |
| - it { is_expected.to eq("default_value") } |
| 126 | + context "and the environment is development" do |
| 127 | + let(:nvar_env) { :development } |
| 128 | + |
| 129 | + it { is_expected.to eq("passthrough_value") } |
| 130 | + end |
| 131 | + |
| 132 | + context "and the environment is test" do |
| 133 | + let(:nvar_env) { :test } |
| 134 | + |
| 135 | + it { is_expected.to eq("default_value") } |
| 136 | + end |
116 | 137 | end
|
117 | 138 |
|
118 | 139 | context "when passthrough is true and a default value is provided" do
|
119 | 140 | let(:args) { base_args.merge(passthrough: true, default_value: "default_value") }
|
120 | 141 |
|
121 |
| - it { is_expected.to eq("passthrough_value") } |
| 142 | + context "and the environment is development" do |
| 143 | + let(:nvar_env) { :development } |
| 144 | + |
| 145 | + it { is_expected.to eq("passthrough_value") } |
| 146 | + end |
| 147 | + |
| 148 | + context "and the environment is test" do |
| 149 | + let(:nvar_env) { :test } |
| 150 | + |
| 151 | + it { is_expected.to eq("passthrough_value") } |
| 152 | + end |
122 | 153 | end
|
123 | 154 |
|
124 | 155 | context "when passthrough is false and a default value is not provided" do
|
125 | 156 | let(:args) { base_args.merge(passthrough: false, default_value: nil) }
|
126 | 157 |
|
127 |
| - it { is_expected.to eq(environment_variable.name) } |
| 158 | + context "and the environment is development" do |
| 159 | + let(:nvar_env) { :development } |
| 160 | + |
| 161 | + it { is_expected.to eq("passthrough_value") } |
| 162 | + end |
| 163 | + |
| 164 | + context "and the environment is test" do |
| 165 | + let(:nvar_env) { :test } |
| 166 | + |
| 167 | + it { is_expected.to eq(environment_variable.name) } |
| 168 | + end |
128 | 169 | end
|
129 | 170 |
|
130 | 171 | context "when passthrough is true and a default value is not provided" do
|
131 | 172 | let(:args) { base_args.merge(passthrough: true, default_value: nil) }
|
132 | 173 |
|
133 |
| - it { is_expected.to eq("passthrough_value") } |
| 174 | + context "and the environment is development" do |
| 175 | + let(:nvar_env) { :development } |
| 176 | + |
| 177 | + it { is_expected.to eq("passthrough_value") } |
| 178 | + end |
| 179 | + |
| 180 | + context "and the environment is test" do |
| 181 | + let(:nvar_env) { :test } |
| 182 | + |
| 183 | + it { is_expected.to eq("passthrough_value") } |
| 184 | + end |
134 | 185 | end
|
135 | 186 |
|
136 | 187 | context "when passthrough is unset in the environment and a default value is not provided" do
|
137 | 188 | let(:args) { base_args.except(:passthrough).merge(default_value: nil) }
|
138 | 189 |
|
139 |
| - it { is_expected.to eq(environment_variable.name) } |
| 190 | + context "and the environment is development" do |
| 191 | + let(:nvar_env) { :development } |
| 192 | + |
| 193 | + it { is_expected.to eq("passthrough_value") } |
| 194 | + end |
| 195 | + |
| 196 | + context "and the environment is test" do |
| 197 | + let(:nvar_env) { :test } |
| 198 | + |
| 199 | + it { is_expected.to eq(environment_variable.name) } |
| 200 | + end |
140 | 201 | end
|
141 | 202 |
|
142 | 203 | context "when passthrough is unset in the environment and a default value is provided" do
|
143 | 204 | let(:args) { base_args.except(:passthrough).merge(default_value: "default_value") }
|
144 | 205 |
|
145 |
| - it { is_expected.to eq("default_value") } |
| 206 | + context "and the environment is development" do |
| 207 | + let(:nvar_env) { :development } |
| 208 | + |
| 209 | + it { is_expected.to eq("passthrough_value") } |
| 210 | + end |
| 211 | + |
| 212 | + context "and the environment is test" do |
| 213 | + let(:nvar_env) { :test } |
| 214 | + |
| 215 | + it { is_expected.to eq("default_value") } |
| 216 | + end |
146 | 217 | end
|
147 | 218 |
|
148 | 219 | context "when passthrough is enabled through the environment and a default value is provided" do
|
149 | 220 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "SOME_OTHER_VAR,#{base_args[:name]}") { example.run } }
|
150 | 221 |
|
151 | 222 | let(:args) { base_args.except(:passthrough).merge(default_value: "default_value") }
|
152 | 223 |
|
153 |
| - it { is_expected.to eq("passthrough_value") } |
| 224 | + context "and the environment is development" do |
| 225 | + let(:nvar_env) { :development } |
| 226 | + |
| 227 | + it { is_expected.to eq("passthrough_value") } |
| 228 | + end |
| 229 | + |
| 230 | + context "and the environment is test" do |
| 231 | + let(:nvar_env) { :test } |
| 232 | + |
| 233 | + it { is_expected.to eq("passthrough_value") } |
| 234 | + end |
154 | 235 | end
|
155 | 236 |
|
156 | 237 | context "when passthrough is enabled through the environment and a default value is not provided" do
|
157 | 238 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "SOME_OTHER_VAR,#{base_args[:name]}") { example.run } }
|
158 | 239 |
|
159 | 240 | let(:args) { base_args.except(:passthrough).merge(default_value: nil) }
|
160 | 241 |
|
161 |
| - it { is_expected.to eq("passthrough_value") } |
| 242 | + context "and the environment is development" do |
| 243 | + let(:nvar_env) { :development } |
| 244 | + |
| 245 | + it { is_expected.to eq("passthrough_value") } |
| 246 | + end |
| 247 | + |
| 248 | + context "and the environment is test" do |
| 249 | + let(:nvar_env) { :test } |
| 250 | + |
| 251 | + it { is_expected.to eq("passthrough_value") } |
| 252 | + end |
162 | 253 | end
|
163 | 254 |
|
164 | 255 | context "when passthrough is enabled through the environment, but is overridden by the config" do
|
165 | 256 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "SOME_OTHER_VAR,#{base_args[:name]}") { example.run } }
|
166 | 257 |
|
167 | 258 | let(:args) { base_args.merge(passthrough: false, default_value: nil) }
|
168 | 259 |
|
169 |
| - it { is_expected.to eq(environment_variable.name) } |
| 260 | + context "and the environment is development" do |
| 261 | + let(:nvar_env) { :development } |
| 262 | + |
| 263 | + it { is_expected.to eq("passthrough_value") } |
| 264 | + end |
| 265 | + |
| 266 | + context "and the environment is test" do |
| 267 | + let(:nvar_env) { :test } |
| 268 | + |
| 269 | + it { is_expected.to eq(environment_variable.name) } |
| 270 | + end |
170 | 271 | end
|
171 | 272 |
|
172 | 273 | context "when passthrough is disabled through the environment and a default value is provided" do
|
173 | 274 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "SOME_OTHER_VAR") { example.run } }
|
174 | 275 |
|
175 | 276 | let(:args) { base_args.except(:passthrough).merge(default_value: "default_value") }
|
176 | 277 |
|
177 |
| - it { is_expected.to eq("default_value") } |
| 278 | + context "and the environment is development" do |
| 279 | + let(:nvar_env) { :development } |
| 280 | + |
| 281 | + it { is_expected.to eq("passthrough_value") } |
| 282 | + end |
| 283 | + |
| 284 | + context "and the environment is test" do |
| 285 | + let(:nvar_env) { :test } |
| 286 | + |
| 287 | + it { is_expected.to eq("default_value") } |
| 288 | + end |
178 | 289 | end
|
179 | 290 |
|
180 | 291 | context "when passthrough is disabled through the environment and a default value is not provided" do
|
181 | 292 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "false") { example.run } }
|
182 | 293 |
|
183 | 294 | let(:args) { base_args.except(:passthrough).merge(default_value: nil) }
|
184 | 295 |
|
185 |
| - it { is_expected.to eq(environment_variable.name) } |
| 296 | + context "and the environment is development" do |
| 297 | + let(:nvar_env) { :development } |
| 298 | + |
| 299 | + it { is_expected.to eq("passthrough_value") } |
| 300 | + end |
| 301 | + |
| 302 | + context "and the environment is test" do |
| 303 | + let(:nvar_env) { :test } |
| 304 | + |
| 305 | + it { is_expected.to eq(environment_variable.name) } |
| 306 | + end |
186 | 307 | end
|
187 | 308 |
|
188 | 309 | context "when passthrough is disabled through the environment, but is overridden by the config" do
|
189 | 310 | around { |example| ClimateControl.modify(NVAR_PASSTHROUGH: "SOME_OTHER_VAR") { example.run } }
|
190 | 311 |
|
191 | 312 | let(:args) { base_args.merge(passthrough: true) }
|
192 | 313 |
|
193 |
| - it { is_expected.to eq("passthrough_value") } |
| 314 | + context "and the environment is development" do |
| 315 | + let(:nvar_env) { :development } |
| 316 | + |
| 317 | + it { is_expected.to eq("passthrough_value") } |
| 318 | + end |
| 319 | + |
| 320 | + context "and the environment is test" do |
| 321 | + let(:nvar_env) { :test } |
| 322 | + |
| 323 | + it { is_expected.to eq("passthrough_value") } |
| 324 | + end |
194 | 325 | end
|
195 | 326 | end
|
196 | 327 | end
|
0 commit comments