Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/mini_sanity/assert.rb
Instance Method Summary collapse
-
#assert!(pattern = MiniSanity::TRUTHY, hint: nil, &block) ⇒ Object
Checks that a given
pattern
matches the Object (or a derivative value), and returns the Object. -
#refute!(pattern = MiniSanity::TRUTHY, hint: nil, &block) ⇒ Object
Checks that a given
pattern
does not match the Object (or a derivative value), and returns the Object.
Instance Method Details
#assert!(pattern = MiniSanity::TRUTHY, hint: nil) ⇒ self #assert!(pattern = MiniSanity::TRUTHY, hint: nil) {|itself| ... } ⇒ self
Checks that a given pattern
matches the Object (or a derivative value), and returns the Object. Raises an exception if the pattern does not match.
If a block is given, the Object is yielded to the block, and the derivative value returned by the block is checked instead.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mini_sanity/assert.rb', line 74 def assert!(pattern = MiniSanity::TRUTHY, hint: nil, &block) result = block ? block.call(self) : self unless pattern === result raise MiniSanity::Error.new("Assert failed", { "Value" => self.inspect, "Derived value (from #{MiniSanity::Error.describe_block(&block) || "block"})" => (result.inspect if block), "Assert matches" => pattern.inspect, "Hint" => hint, }) end self end |
#refute!(pattern = MiniSanity::TRUTHY, hint: nil) ⇒ self #refute!(pattern = MiniSanity::TRUTHY, hint: nil) {|itself| ... } ⇒ self
Checks that a given pattern
does not match the Object (or a derivative value), and returns the Object. Raises an exception if the pattern matches.
If a block is given, the Object is yielded to the block, and the derivative value returned by the block is checked instead.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mini_sanity/assert.rb', line 147 def refute!(pattern = MiniSanity::TRUTHY, hint: nil, &block) result = block ? block.call(self) : self if pattern === result raise MiniSanity::Error.new("Refute failed", { "Value" => self.inspect, "Derived value (from #{MiniSanity::Error.describe_block(&block) || "block"})" => (result.inspect if block), "Refute matches" => pattern.inspect, "Hint" => hint, }) end self end |