Skip to content
代码片段 群组 项目
用户头像
Dylan Griffith 编辑于
In real usage if you call `ENV.fetch('NON_EXISTENT_KEY')` it will raise
a `KeyError`. But our previously implementation of of `stub_env` with
`nil` is causing it to return `nil` rather than raising an error. This
can cause us to write tests that don't match the actual production
behaviour. We might forget to rescue the exception in a certain place or
we also may not be able to write a test case for the expected behaviour.

```
irb(main):001> ENV.fetch('NON_EXISTENT_KEY')
(irb):1:in `fetch': key not found: "NON_EXISTENT_KEY" (KeyError)

irb(main):002> ENV['NON_EXISTENT_KEY'] = nil
=> nil

irb(main):003> ENV.fetch('NON_EXISTENT_KEY')
(irb):3:in `fetch': key not found: "NON_EXISTENT_KEY" (KeyError)
```
2a8aefca
历史
代码所有者
将用户和群组指定为特定文件更改的核准人。 了解更多。