From 651127f2d40756f02c31550f141370047f4627c0 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Jan 2019 17:09:24 -0700 Subject: [PATCH] Add spec for empty matcher Mark question matchers as done (for now). More may be added later if they're common. --- README.md | 2 +- spec/matchers/empty_matcher_spec.cr | 43 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 spec/matchers/empty_matcher_spec.cr diff --git a/README.md b/README.md index 7050b15..d6f7261 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ In no particular order, features that have been implemented and are planned: - [X] Equality matchers - `eq`, `be`, `be_a`, `match` - [X] Truthy matchers - `be_true`, `be_false`, `be_truthy`, `be_falsey` - [X] Comparison matchers - `<`, `<=`, `>`, `>=`, `be_within` - - [ ] Question matchers - `be_nil`, `be_xxx` + - [X] Question matchers - `be_nil`, `be_empty` - [ ] Exception matchers - `raise_error` - [ ] Collection matchers - `start_with`, `end_with`, `contain`, `contain_exactly` - [ ] Change matchers - `change`, `from`, `to`, `by`, `by_at_least`, `by_at_most` diff --git a/spec/matchers/empty_matcher_spec.cr b/spec/matchers/empty_matcher_spec.cr new file mode 100644 index 0000000..79bdc43 --- /dev/null +++ b/spec/matchers/empty_matcher_spec.cr @@ -0,0 +1,43 @@ +require "../spec_helper" + +describe Spectator::Matchers::EmptyMatcher do + describe "#match?" do + context "with an empty set" do + it "is true" do + array = [] of Symbol + partial = Spectator::Expectations::ValueExpectationPartial.new(array) + matcher = Spectator::Matchers::EmptyMatcher.new + matcher.match?(partial).should be_true + end + end + + context "with a filled set" do + it "is false" do + array = %i[a b c] + partial = Spectator::Expectations::ValueExpectationPartial.new(array) + matcher = Spectator::Matchers::EmptyMatcher.new + matcher.match?(partial).should be_false + end + end + end + + describe "#message" do + it "contains the actual label" do + array = %i[a b c] + label = "everything" + partial = Spectator::Expectations::ValueExpectationPartial.new(label, array) + matcher = Spectator::Matchers::EmptyMatcher.new + matcher.message(partial).should contain(label) + end + end + + describe "#negated_message" do + it "contains the actual label" do + array = %i[a b c] + label = "everything" + partial = Spectator::Expectations::ValueExpectationPartial.new(label, array) + matcher = Spectator::Matchers::EmptyMatcher.new + matcher.negated_message(partial).should contain(label) + end + end +end