markbates / markbates/configatron
Nested 'temp' creating some unexpected behavior
- Dominant language
- Ruby
- Stars
- 593
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Description
In our tests, we make use of rspec's before/after/around lifecycle hooks to set the state of the test, including configatron settings with `configatron.temp`. Unfortunately when you have multiple `configatron.temp` competing with each other (one wrapping the other basically), it produces some results that we didn't expect:
```
[3] pry(main)> configatron.foo = 1
1
[4] pry(main)> configatron.temp do
[4] pry(main)* configatron.foo = 2
[4] pry(main)* configatron.temp do
[4] pry(main)* configatron.foo = 3
[4] pry(main)* end
[4] pry(main)* end
3
[5] pry(main)>
[6] pry(main)> configatron.foo
2
```
In this example, our our tests assumed that the settings would be returned to their original state, which in this example would be `configatron.foo = 1`
Is there a more elegant way to achieve what we want here with `temp`? In the short term, we've restored to manually holding the state of the variable we are setting and then resetting it at the end of the `before`/`around` block
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the nested configatron.temp example and then trace the temp implementation and its existing tests. Check how nested RSpec before/after/around usage restores state; done means an inner temp scope does not overwrite the outer scope's eventual restoration, returning configatron.foo to its original value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100