diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:38 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:38 +0100 |
commit | 44736a6b7a2b3475db2d05187f33e3c1a7b4b4e5 (patch) | |
tree | 4cb679a8742121782a50e72e01160d19f479f9a6 /spec/mspec/lib/mspec/expectations/should.rb | |
parent | 31ae931e166825450dcc16d470553e67281951a2 (diff) |
Update to ruby/mspec@d1adf59
Diffstat (limited to 'spec/mspec/lib/mspec/expectations/should.rb')
-rw-r--r-- | spec/mspec/lib/mspec/expectations/should.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/spec/mspec/lib/mspec/expectations/should.rb b/spec/mspec/lib/mspec/expectations/should.rb index ca0617484c..c1790e0ac8 100644 --- a/spec/mspec/lib/mspec/expectations/should.rb +++ b/spec/mspec/lib/mspec/expectations/should.rb @@ -1,7 +1,7 @@ class Object NO_MATCHER_GIVEN = Object.new - def should(matcher = NO_MATCHER_GIVEN) + def should(matcher = NO_MATCHER_GIVEN, &block) MSpec.expectation state = MSpec.current.state raise "should outside example" unless state @@ -10,6 +10,9 @@ class Object if NO_MATCHER_GIVEN.equal?(matcher) SpecPositiveOperatorMatcher.new(self) else + # The block was given to #should syntactically, but it was intended for a matcher like #raise_error + matcher.block = block if block + unless matcher.matches? self expected, actual = matcher.failure_message SpecExpectation.fail_with(expected, actual) @@ -17,7 +20,7 @@ class Object end end - def should_not(matcher = NO_MATCHER_GIVEN) + def should_not(matcher = NO_MATCHER_GIVEN, &block) MSpec.expectation state = MSpec.current.state raise "should_not outside example" unless state @@ -26,6 +29,9 @@ class Object if NO_MATCHER_GIVEN.equal?(matcher) SpecNegativeOperatorMatcher.new(self) else + # The block was given to #should_not syntactically, but it was intended for the matcher + matcher.block = block if block + if matcher.matches? self expected, actual = matcher.negative_failure_message SpecExpectation.fail_with(expected, actual) |