redding / assert

Assertion style testing framework.
https://github.com/redding/assert
MIT License
10 stars 1 forks source link

memoize `subject`s; update tests to use memoized subjects #299

Closed kellyredding closed 4 years ago

kellyredding commented 4 years ago

This updates the Assert::Context#subject to memoize its return values. I can't remember why we never memoized the subject before but now that we have memoized lets, it feels awkward/unexpected to not have memoized subjects.

This also updates the test suite to make use of the memoized subjects. We had many let's that were only there to be memoized subject values. They are unnecessary if subjects are implicitly memoized.

Note: this also updates the instance variable name used to memoize lets to use the @__assert_{whatever}__ naming convention. This keeps lets from polluting the instance variable namespace and conflicting with instance variables created in setup blocks.

Note: I chose to switch-to/use instance_variable_defined? b/c both subjects and lets can be nil so this isn't a good memoization signal. A better signal is whether an instance method is defined or not. This allows nil values to get memoized and not re-processed.