diff options
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") |