From 8c6552a99596adb3693540c60dc0576c484d99aa Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 23 Jan 2019 15:51:52 -0700 Subject: [PATCH] Add DSL for `be_truthy` and `be_falsey` --- src/spectator/dsl/matcher_dsl.cr | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index c04dd64..94db68c 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -79,5 +79,29 @@ module Spectator::DSL macro be_false eq(false) end + + # Indicates that some value should be truthy. + # This means that the value is not `false` and not `nil`. + # + # Examples: + # ``` + # expect(123).to be_truthy + # expect(true).to be_truthy + # ``` + macro be_truthy + ::Spectator::Matchers::TruthyMatcher.new(true) + end + + # Indicates that some value should be falsey. + # This means that the value is either `false` or `nil`. + # + # Examples: + # ``` + # expect(false).to be_falsey + # expect(nil).to be_falsey + # ``` + macro be_falsey + ::Spectator::Matchers::TruthyMatcher.new(false) + end end end