summaryrefslogtreecommitdiff
path: root/spec/mspec/spec
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-05-31 18:22:47 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-05-31 18:22:47 +0200
commitf4502b001a665109bf776f9037ecbc52cb5f2d88 (patch)
treed960ce72fca89876a7bf8c404c44e60b2ccb2441 /spec/mspec/spec
parent5a79d8e0507cd143100bf928a88a59a8b5a5bca6 (diff)
Update to ruby/mspec@e3abf6b
Diffstat (limited to 'spec/mspec/spec')
-rw-r--r--spec/mspec/spec/matchers/raise_error_spec.rb53
-rw-r--r--spec/mspec/spec/runner/exception_spec.rb2
2 files changed, 41 insertions, 14 deletions
diff --git a/spec/mspec/spec/matchers/raise_error_spec.rb b/spec/mspec/spec/matchers/raise_error_spec.rb
index 1ed794e0a9..a40acc0ea0 100644
--- a/spec/mspec/spec/matchers/raise_error_spec.rb
+++ b/spec/mspec/spec/matchers/raise_error_spec.rb
@@ -12,7 +12,7 @@ describe RaiseErrorMatcher do
matcher.matches?(proc).should == true
end
- it "executes it's optional block if matched" do
+ it "executes its optional block if matched" do
run = false
proc = Proc.new { raise ExpectedException }
matcher = RaiseErrorMatcher.new(ExpectedException, nil) { |error|
@@ -62,16 +62,21 @@ describe RaiseErrorMatcher do
matcher.matches?(proc).should == false
end
- it "provides a useful failure message" do
- exc = UnexpectedException.new("unexpected")
- matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
+ it "provides a useful failure message when the exception class differs" do
+ exc = UnexpectedException.new("message")
+ matcher = RaiseErrorMatcher.new(ExpectedException, "message")
matcher.matching_exception?(exc).should == false
- lambda {
+ begin
matcher.matches?(Proc.new { raise exc })
- }.should raise_error(UnexpectedException)
- matcher.failure_message.should ==
- ["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"]
+ rescue UnexpectedException => e
+ matcher.failure_message.should ==
+ ["Expected ExpectedException (message)", "but got: UnexpectedException (message)"]
+ ExceptionState.new(nil, nil, e).message.should ==
+ "Expected ExpectedException (message)\nbut got: UnexpectedException (message)"
+ else
+ raise "no exception"
+ end
end
it "provides a useful failure message when the proc raises the expected exception with an unexpected message" do
@@ -79,11 +84,33 @@ describe RaiseErrorMatcher do
matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
matcher.matching_exception?(exc).should == false
- lambda {
+ begin
matcher.matches?(Proc.new { raise exc })
- }.should raise_error(ExpectedException)
- matcher.failure_message.should ==
- ["Expected ExpectedException (expected)", "but got ExpectedException (unexpected)"]
+ rescue ExpectedException => e
+ matcher.failure_message.should ==
+ ["Expected ExpectedException (expected)", "but got: ExpectedException (unexpected)"]
+ ExceptionState.new(nil, nil, e).message.should ==
+ "Expected ExpectedException (expected)\nbut got: ExpectedException (unexpected)"
+ else
+ raise "no exception"
+ end
+ end
+
+ it "provides a useful failure message when both the exception class and message differ" do
+ exc = UnexpectedException.new("unexpected")
+ matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
+
+ matcher.matching_exception?(exc).should == false
+ begin
+ matcher.matches?(Proc.new { raise exc })
+ rescue UnexpectedException => e
+ matcher.failure_message.should ==
+ ["Expected ExpectedException (expected)", "but got: UnexpectedException (unexpected)"]
+ ExceptionState.new(nil, nil, e).message.should ==
+ "Expected ExpectedException (expected)\nbut got: UnexpectedException (unexpected)"
+ else
+ raise "no exception"
+ end
end
it "provides a useful failure message when no exception is raised" do
@@ -127,6 +154,6 @@ describe RaiseErrorMatcher do
matcher = RaiseErrorMatcher.new(Exception, nil)
matcher.matches?(proc)
matcher.negative_failure_message.should ==
- ["Expected to not get Exception", "but got UnexpectedException (unexpected)"]
+ ["Expected to not get Exception", "but got: UnexpectedException (unexpected)"]
end
end
diff --git a/spec/mspec/spec/runner/exception_spec.rb b/spec/mspec/spec/runner/exception_spec.rb
index 309442435c..0e0a819992 100644
--- a/spec/mspec/spec/runner/exception_spec.rb
+++ b/spec/mspec/spec/runner/exception_spec.rb
@@ -93,7 +93,7 @@ describe ExceptionState, "#message" do
it "returns <No message> if the exception message is empty" do
exc = ExceptionState.new @state, "", Exception.new("")
- exc.message.should == "<No message>"
+ exc.message.should == "Exception: <No message>"
end
it "returns the message without exception class when the exception is an SpecExpectationNotMetError" do