summaryrefslogtreecommitdiff
path: root/spec/mspec/lib
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2021-03-27 13:02:38 +0100
committerBenoit Daloze <[email protected]>2021-03-27 13:02:38 +0100
commit44736a6b7a2b3475db2d05187f33e3c1a7b4b4e5 (patch)
tree4cb679a8742121782a50e72e01160d19f479f9a6 /spec/mspec/lib
parent31ae931e166825450dcc16d470553e67281951a2 (diff)
Update to ruby/mspec@d1adf59
Diffstat (limited to 'spec/mspec/lib')
-rw-r--r--spec/mspec/lib/mspec/expectations/should.rb10
-rw-r--r--spec/mspec/lib/mspec/helpers/warning.rb2
-rw-r--r--spec/mspec/lib/mspec/matchers/raise_error.rb2
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/junit.rb6
4 files changed, 15 insertions, 5 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)
diff --git a/spec/mspec/lib/mspec/helpers/warning.rb b/spec/mspec/lib/mspec/helpers/warning.rb
index f94551c185..e3d72b78bd 100644
--- a/spec/mspec/lib/mspec/helpers/warning.rb
+++ b/spec/mspec/lib/mspec/helpers/warning.rb
@@ -1,5 +1,7 @@
require 'mspec/guards/version'
+# You might be looking for #silence_warnings, use #suppress_warning instead.
+# MSpec calls it #suppress_warning for consistency with EnvUtil.suppress_warning in CRuby test/.
def suppress_warning
verbose = $VERBOSE
$VERBOSE = nil
diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb
index 878428d43a..0ee8953519 100644
--- a/spec/mspec/lib/mspec/matchers/raise_error.rb
+++ b/spec/mspec/lib/mspec/matchers/raise_error.rb
@@ -1,4 +1,6 @@
class RaiseErrorMatcher
+ attr_writer :block
+
def initialize(exception, message, &block)
@exception = exception
@message = message
diff --git a/spec/mspec/lib/mspec/runner/formatters/junit.rb b/spec/mspec/lib/mspec/runner/formatters/junit.rb
index 12e43a3263..6351ccbce9 100644
--- a/spec/mspec/lib/mspec/runner/formatters/junit.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/junit.rb
@@ -24,7 +24,7 @@ class JUnitFormatter < YamlFormatter
errors = @tally.counter.errors
failures = @tally.counter.failures
- printf <<-XML
+ print <<-XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites
@@ -42,8 +42,8 @@ class JUnitFormatter < YamlFormatter
@tests.each do |h|
description = encode_for_xml h[:test].description
- printf <<-XML, "Spec", description, 0.0
- <testcase classname="%s" name="%s" time="%f">
+ print <<-XML
+ <testcase classname="Spec" name="#{description}" time="0.0">
XML
if h[:exception]
outcome = h[:test].failure? ? "failure" : "error"