summaryrefslogtreecommitdiff
path: root/spec/mspec/lib
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 15:56:09 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 15:56:09 +0000
commit49a864ad902c7e819f2464f1001e9719a9af6cb5 (patch)
tree3b084371c3dfc8cb6eda885094b9470014c8e48b /spec/mspec/lib
parent3efe410dd0812a3781b9f75a52d67a632009b2d2 (diff)
Update to ruby/mspec@5bd9409
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/mspec/lib')
-rw-r--r--spec/mspec/lib/mspec/matchers/raise_error.rb10
-rw-r--r--spec/mspec/lib/mspec/mocks/mock.rb15
-rw-r--r--spec/mspec/lib/mspec/runner/formatters/multi.rb3
-rw-r--r--spec/mspec/lib/mspec/runner/mspec.rb6
-rw-r--r--spec/mspec/lib/mspec/utils/script.rb4
-rw-r--r--spec/mspec/lib/mspec/utils/warnings.rb19
6 files changed, 47 insertions, 10 deletions
diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb
index d128ca03ea..28c7a5ea2f 100644
--- a/spec/mspec/lib/mspec/matchers/raise_error.rb
+++ b/spec/mspec/lib/mspec/matchers/raise_error.rb
@@ -5,16 +5,18 @@ class RaiseErrorMatcher
@exception = exception
@message = message
@block = block
+ @actual = nil
end
def matches?(proc)
@result = proc.call
return false
- rescue Exception => @actual
- if matching_exception?(@actual)
+ rescue Exception => actual
+ @actual = actual
+ if matching_exception?(actual)
return true
else
- raise @actual
+ raise actual
end
end
@@ -54,7 +56,7 @@ class RaiseErrorMatcher
def failure_message
message = ["Expected #{format_expected_exception}"]
- if @actual then
+ if @actual
message << "but got #{format_exception(@actual)}"
else
message << "but no exception was raised (#{@result.pretty_inspect.chomp} was returned)"
diff --git a/spec/mspec/lib/mspec/mocks/mock.rb b/spec/mspec/lib/mspec/mocks/mock.rb
index 9fc72b5631..f833cba371 100644
--- a/spec/mspec/lib/mspec/mocks/mock.rb
+++ b/spec/mspec/lib/mspec/mocks/mock.rb
@@ -1,4 +1,5 @@
require 'mspec/expectations/expectations'
+require 'mspec/helpers/warning'
module Mock
def self.reset
@@ -57,10 +58,12 @@ module Mock
meta.__send__ :alias_method, key.first, sym
end
- meta.class_eval {
- define_method(sym) do |*args, &block|
- Mock.verify_call self, sym, *args, &block
- end
+ suppress_warning {
+ meta.class_eval {
+ define_method(sym) do |*args, &block|
+ Mock.verify_call self, sym, *args, &block
+ end
+ }
}
proxy = MockProxy.new type
@@ -179,7 +182,9 @@ module Mock
meta = obj.singleton_class
if mock_respond_to? obj, replaced, true
- meta.__send__ :alias_method, sym, replaced
+ suppress_warning do
+ meta.__send__ :alias_method, sym, replaced
+ end
meta.__send__ :remove_method, replaced
else
meta.__send__ :remove_method, sym
diff --git a/spec/mspec/lib/mspec/runner/formatters/multi.rb b/spec/mspec/lib/mspec/runner/formatters/multi.rb
index bcc5411e6f..f69055025f 100644
--- a/spec/mspec/lib/mspec/runner/formatters/multi.rb
+++ b/spec/mspec/lib/mspec/runner/formatters/multi.rb
@@ -1,5 +1,4 @@
require 'mspec/runner/formatters/spinner'
-require 'yaml'
class MultiFormatter < SpinnerFormatter
def initialize(out=nil)
@@ -10,6 +9,8 @@ class MultiFormatter < SpinnerFormatter
end
def aggregate_results(files)
+ require 'yaml'
+
@timer.finish
@exceptions = []
diff --git a/spec/mspec/lib/mspec/runner/mspec.rb b/spec/mspec/lib/mspec/runner/mspec.rb
index 8f9c7a602f..d47657326b 100644
--- a/spec/mspec/lib/mspec/runner/mspec.rb
+++ b/spec/mspec/lib/mspec/runner/mspec.rb
@@ -2,6 +2,9 @@ require 'mspec/runner/context'
require 'mspec/runner/exception'
require 'mspec/runner/tag'
+module MSpec
+end
+
class MSpecEnv
include MSpec
end
@@ -399,4 +402,7 @@ module MSpec
file = tags_file
File.delete file if File.exist? file
end
+
+ # Initialize @env
+ setup_env
end
diff --git a/spec/mspec/lib/mspec/utils/script.rb b/spec/mspec/lib/mspec/utils/script.rb
index 1c7d0aeb52..0c8922c4a8 100644
--- a/spec/mspec/lib/mspec/utils/script.rb
+++ b/spec/mspec/lib/mspec/utils/script.rb
@@ -38,6 +38,10 @@ class MSpecScript
end
def initialize
+ if RUBY_VERSION < '2.2'
+ abort "MSpec needs Ruby 2.2 or more recent"
+ end
+
config[:formatter] = nil
config[:includes] = []
config[:excludes] = []
diff --git a/spec/mspec/lib/mspec/utils/warnings.rb b/spec/mspec/lib/mspec/utils/warnings.rb
index 74c7f88a52..ef5e5c692c 100644
--- a/spec/mspec/lib/mspec/utils/warnings.rb
+++ b/spec/mspec/lib/mspec/utils/warnings.rb
@@ -4,6 +4,7 @@ if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0"
ruby_version_is "2.4"..."2.5" do
# Kernel#warn does not delegate to Warning.warn in 2.4
module Kernel
+ remove_method :warn
def warn(*messages)
return if $VERBOSE == nil or messages.empty?
msg = messages.join("\n")
@@ -16,6 +17,24 @@ if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0"
def Warning.warn(message)
case message
+ # $VERBOSE = true warnings
+ when /possibly useless use of (<|<=|==|>=|>|\+|-) in void context/
+ when /assigned but unused variable/
+ when /method redefined/
+ when /previous definition of/
+ when /instance variable @.+ not initialized/
+ when /statement not reached/
+ when /shadowing outer local variable/
+ when /setting Encoding.default_(in|ex)ternal/
+ when /unknown (un)?pack directive/
+ when /(un)?trust(ed\?)? is deprecated/
+ when /\.exists\? is a deprecated name/
+ when /Float .+ out of range/
+ when /passing a block to String#(bytes|chars|codepoints|lines) is deprecated/
+ when /core\/string\/modulo_spec\.rb:\d+: warning: too many arguments for format string/
+ when /regexp\/shared\/new_ascii(_8bit)?\.rb:\d+: warning: Unknown escape .+ is ignored/
+
+ # $VERBOSE = false warnings
when /constant ::(Fixnum|Bignum) is deprecated/
when /\/(argf|io|stringio)\/.+(ARGF|IO)#(lines|chars|bytes|codepoints) is deprecated/
when /Thread\.exclusive is deprecated.+\n.+thread\/exclusive_spec\.rb/