redding / assert

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

add Assert::Context::LetDSL #296

Closed kellyredding closed 4 years ago

kellyredding commented 4 years ago

This adds a let DSL method for declaring test input values. These create local methods to instance_eval the block and memoize its return value.

The benefit of using lets instead of manually defining methods for test inputs is that lets auto-memoize for you and put the value declarations at the beginning of the test context definition.

The benefit of using lets instead of e.g. setting an instance variable in a setup block, is that they are late-bound and the value is only memoized if the let method is called.

Other Changes

rewrite Assert's test suite to use lets

Now that this feature is available, switch to using it in the test suite. This implicitly tests using lets in a rich varied set of circumstances. This also slightly improves the performance of running the test suite due to the late-bound nature of lets.

add Assert::Context::MethodMissing mix-in

This moves the method_missing logic out of Assert::Assertions and into its own dedicated mix-in as the method missing handling on a context isn't really specific to assertions.