diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-20 20:38:27 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-20 20:38:27 +0000 |
commit | 58573c33e4720315ed27491e31dcc22892e1ce95 (patch) | |
tree | 336d0c3c193555a82e0d2ad8175e7f7bfcc76b30 /spec/mspec/spec | |
parent | 1c53f86bd9701abd6c6d3a787541e5c408f5aef9 (diff) | |
download | ruby-58573c33e4720315ed27491e31dcc22892e1ce95.tar.gz |
Update to ruby/mspec@e9a482d
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/mspec/spec')
-rw-r--r-- | spec/mspec/spec/matchers/complain_spec.rb | 45 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/raise_error_spec.rb | 12 |
2 files changed, 57 insertions, 0 deletions
diff --git a/spec/mspec/spec/matchers/complain_spec.rb b/spec/mspec/spec/matchers/complain_spec.rb index 709b57be6c..83ecb70622 100644 --- a/spec/mspec/spec/matchers/complain_spec.rb +++ b/spec/mspec/spec/matchers/complain_spec.rb @@ -49,4 +49,49 @@ describe ComplainMatcher do matcher.negative_failure_message.should == ["Expected warning not to match: /ou/", "but got: \"ouch\""] end + + context "`verbose` option specified" do + before do + $VERBOSE, @verbose = nil, $VERBOSE + end + + after do + $VERBOSE = @verbose + end + + it "sets $VERBOSE with specified second optional parameter" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(nil, verbose: true).matches?(proc) + verbose.should == true + + ComplainMatcher.new(nil, verbose: false).matches?(proc) + verbose.should == false + end + + it "sets $VERBOSE with false by default" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(nil).matches?(proc) + verbose.should == false + end + + it "does not have side effect" do + proc = lambda { safe_value = $VERBOSE } + + lambda do + ComplainMatcher.new(nil, verbose: true).matches?(proc) + end.should_not change { $VERBOSE } + end + + it "accepts a verbose level as single argument" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(verbose: true).matches?(proc) + verbose.should == true + end + end end diff --git a/spec/mspec/spec/matchers/raise_error_spec.rb b/spec/mspec/spec/matchers/raise_error_spec.rb index 7c93f0f64c..28e1ea69a7 100644 --- a/spec/mspec/spec/matchers/raise_error_spec.rb +++ b/spec/mspec/spec/matchers/raise_error_spec.rb @@ -74,6 +74,18 @@ describe RaiseErrorMatcher do ["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"] end + it "provides a useful failure message when the proc raises the expected exception with an unexpected message" do + exc = ExpectedException.new("unexpected") + matcher = RaiseErrorMatcher.new(ExpectedException, "expected") + + matcher.matching_exception?(exc).should == false + lambda { + matcher.matches?(Proc.new { raise exc }) + }.should raise_error(ExpectedException) + matcher.failure_message.should == + ["Expected ExpectedException (expected)", "but got ExpectedException (unexpected)"] + end + it "provides a useful failure message when no exception is raised" do proc = Proc.new { 120 } matcher = RaiseErrorMatcher.new(ExpectedException, "expected") |