Skip to content

Commit d3edf25

Browse files
committed
Support -> { ... }.should.raise(SomeException, "message", cause:)
* Like `should raise_error(SomeException, "message", cause:)` but using the `should.` syntax.
1 parent 9f00217 commit d3edf25

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

lib/mspec/matchers/base.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def equal?(expected)
3636
end
3737
end
3838

39+
def raise(exception = Exception, message = nil, options = nil, &block)
40+
matcher = ::RaiseErrorMatcher.new(exception, message, options, &block)
41+
unless matcher.matches? @actual
42+
expected, actual = matcher.failure_message
43+
::SpecExpectation.fail_with(expected, actual)
44+
end
45+
end
46+
3947
def method_missing(name, *args, &block)
4048
result = @actual.__send__(name, *args, &block)
4149
unless result
@@ -70,6 +78,14 @@ def equal?(expected)
7078
end
7179
end
7280

81+
def raise(exception = Exception, message = nil, options = nil, &block)
82+
matcher = ::RaiseErrorMatcher.new(exception, message, options, &block)
83+
if matcher.matches? @actual
84+
expected, actual = matcher.negative_failure_message
85+
::SpecExpectation.fail_with(expected, actual)
86+
end
87+
end
88+
7389
def method_missing(name, *args, &block)
7490
result = @actual.__send__(name, *args, &block)
7591
if result

0 commit comments

Comments
 (0)