Add DSL for be_close matcher

This commit is contained in:
Michael Miller 2019-02-01 19:10:28 -07:00
parent 196b4d97a5
commit 5389a39231
2 changed files with 16 additions and 1 deletions

View file

@ -112,7 +112,7 @@ In no particular order, features that have been implemented and are planned:
- [ ] Shared examples - `behaves_like`, `include_examples` - [ ] Shared examples - `behaves_like`, `include_examples`
- [ ] Matchers - [ ] Matchers
- [X] Equality matchers - `eq`, `ne`, `be ==`, `be !=` - [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` - [ ] 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` - [ ] 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` - [X] Truthy matchers - `be`, `be_true`, `be_truthy`, `be_false`, `be_falsey`, `be_nil`

View file

@ -263,6 +263,21 @@ module Spectator::DSL
) )
end 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. # Indicates that some value should or should not be nil.
# #
# Examples: # Examples: