diff --git a/README.md b/README.md index 4bd520f..86c18df 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ In no particular order, features that have been implemented and are planned: - [ ] Shared examples - `behaves_like`, `include_examples` - [ ] Matchers - [X] Equality matchers - `eq`, `ne`, `be ==`, `be !=` - - [ ] Comparison matchers - `lt`, `le`, `gt`, `ge`, `be <`, `be <=`, `be >`, `be >=`, `be_within[.of]`, `be_close` + - [X] Comparison matchers - `lt`, `le`, `gt`, `ge`, `be <`, `be <=`, `be >`, `be >=`, `be_within[.of]`, `be_close` - [ ] Type matchers - `be_a`, `respond_to` - [ ] Collection matchers - `contain`, `have`, `contain_exactly[.in_order|.in_any_order]`, `match_array[.in_order|.in_any_order]`, `start_with`, `end_with`, `be_empty`, `has_key`, `has_value`, `all`, `all_satisfy` - [X] Truthy matchers - `be`, `be_true`, `be_truthy`, `be_false`, `be_falsey`, `be_nil` diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index 1ab1bcf..9a6f427 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -263,6 +263,21 @@ module Spectator::DSL ) end + # Indicates that some value should be within a delta of an expected value. + # + # Example: + # ``` + # expect(pi).to be_close(3.14159265359, 0.0000001) + # ``` + # + # This is functionly equivalent to: + # ``` + # be_within(expected).of(delta) + # ``` + macro be_close(expected, delta) + be_within({{delta}}).of({{expected}}) + end + # Indicates that some value should or should not be nil. # # Examples: