Method: Object#assert!
- Defined in:
- lib/mini_sanity/assert.rb
#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 |