From 58573c33e4720315ed27491e31dcc22892e1ce95 Mon Sep 17 00:00:00 2001 From: eregon Date: Sun, 20 Jan 2019 20:38:27 +0000 Subject: Update to ruby/mspec@e9a482d git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/mspec/lib/mspec/matchers/complain.rb | 19 ++++++++++++++----- spec/mspec/lib/mspec/matchers/raise_error.rb | 7 ++++--- spec/mspec/lib/mspec/utils/warnings.rb | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) (limited to 'spec/mspec/lib') diff --git a/spec/mspec/lib/mspec/matchers/complain.rb b/spec/mspec/lib/mspec/matchers/complain.rb index 4bcb255040..22b8be17e1 100644 --- a/spec/mspec/lib/mspec/matchers/complain.rb +++ b/spec/mspec/lib/mspec/matchers/complain.rb @@ -1,8 +1,17 @@ require 'mspec/helpers/io' class ComplainMatcher - def initialize(complaint) - @complaint = complaint + def initialize(complaint = nil, options = nil) + # the proper solution is to use double splat operator e.g. + # def initialize(complaint = nil, **options) + # but we are trying to minimize language features required to run MSpec + if complaint.is_a?(Hash) + @complaint = nil + @options = complaint + else + @complaint = complaint + @options = options || {} + end end def matches?(proc) @@ -10,7 +19,7 @@ class ComplainMatcher @verbose = $VERBOSE begin err = $stderr = IOStub.new - $VERBOSE = false + $VERBOSE = @options.key?(:verbose) ? @options[:verbose] : false Thread.current[:in_mspec_complain_matcher] = true proc.call ensure @@ -54,7 +63,7 @@ class ComplainMatcher end module MSpecMatchers - private def complain(complaint=nil) - ComplainMatcher.new(complaint) + private def complain(complaint = nil, options = nil) + ComplainMatcher.new(complaint, options) end end diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb index a051ea12f7..8350e25794 100644 --- a/spec/mspec/lib/mspec/matchers/raise_error.rb +++ b/spec/mspec/lib/mspec/matchers/raise_error.rb @@ -12,6 +12,9 @@ class RaiseErrorMatcher rescue Exception => actual @actual = actual if matching_exception?(actual) + # The block has its own expectations and will throw an exception if it fails + @block[actual] if @block + return true else raise actual @@ -20,6 +23,7 @@ class RaiseErrorMatcher def matching_exception?(exc) return false unless @exception === exc + if @message then case @message when String @@ -29,9 +33,6 @@ class RaiseErrorMatcher end end - # The block has its own expectations and will throw an exception if it fails - @block[exc] if @block - return true end diff --git a/spec/mspec/lib/mspec/utils/warnings.rb b/spec/mspec/lib/mspec/utils/warnings.rb index 4d23474236..7c2bc6fe88 100644 --- a/spec/mspec/lib/mspec/utils/warnings.rb +++ b/spec/mspec/lib/mspec/utils/warnings.rb @@ -51,7 +51,7 @@ if RUBY_ENGINE == "ruby" and ruby_version_is("2.4") when /hash\/shared\/index\.rb:\d+: warning: Hash#index is deprecated; use Hash#key/ when /env\/shared\/key\.rb:\d+: warning: ENV\.index is deprecated; use ENV\.key/ when /exponent(_spec)?\.rb:\d+: warning: in a\*\*b, b may be too big/ - when /enumerator\/(new|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/ + when /enumerator\/(new_spec|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/ else $stderr.write message end -- cgit v1.2.3