aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/lib
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:14:55 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:14:55 +0000
commit974e862db9f6c91dc9448570d1a103aad357a6e5 (patch)
tree02c6ae19120f92f7aea5d691be9e9a20618be7e7 /spec/mspec/lib
parentad1b64d35d7ca980a0398f09cff527d7420cd5c1 (diff)
downloadruby-974e862db9f6c91dc9448570d1a103aad357a6e5.tar.gz
Update to ruby/mspec@90925d6
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/mspec/lib')
-rwxr-xr-xspec/mspec/lib/mspec/commands/mspec.rb3
-rw-r--r--spec/mspec/lib/mspec/matchers/complain.rb34
-rw-r--r--spec/mspec/lib/mspec/matchers/raise_error.rb8
-rw-r--r--spec/mspec/lib/mspec/runner/context.rb2
-rw-r--r--spec/mspec/lib/mspec/utils/script.rb34
-rw-r--r--spec/mspec/lib/mspec/utils/warnings.rb14
6 files changed, 59 insertions, 36 deletions
diff --git a/spec/mspec/lib/mspec/commands/mspec.rb b/spec/mspec/lib/mspec/commands/mspec.rb
index cb1c0fbacb..6cb1e87a58 100755
--- a/spec/mspec/lib/mspec/commands/mspec.rb
+++ b/spec/mspec/lib/mspec/commands/mspec.rb
@@ -37,7 +37,7 @@ class MSpecMain < MSpecScript
options.targets
- options.on("--warnings", "Don't supress warnings") do
+ options.on("--warnings", "Don't suppress warnings") do
config[:flags] << '-w'
ENV['OUTPUT_WARNINGS'] = '1'
end
@@ -171,6 +171,7 @@ class MSpecMain < MSpecScript
exit multi_exec(argv)
else
$stderr.puts "$ #{argv.join(' ')}"
+ $stderr.flush
exec(*argv, close_others: false)
end
end
diff --git a/spec/mspec/lib/mspec/matchers/complain.rb b/spec/mspec/lib/mspec/matchers/complain.rb
index 71b6a77680..4bcb255040 100644
--- a/spec/mspec/lib/mspec/matchers/complain.rb
+++ b/spec/mspec/lib/mspec/matchers/complain.rb
@@ -7,44 +7,48 @@ class ComplainMatcher
def matches?(proc)
@saved_err = $stderr
- @stderr = $stderr = IOStub.new
@verbose = $VERBOSE
- $VERBOSE = false
-
- proc.call
+ begin
+ err = $stderr = IOStub.new
+ $VERBOSE = false
+ Thread.current[:in_mspec_complain_matcher] = true
+ proc.call
+ ensure
+ $VERBOSE = @verbose
+ $stderr = @saved_err
+ Thread.current[:in_mspec_complain_matcher] = false
+ end
+ @warning = err.to_s
unless @complaint.nil?
case @complaint
when Regexp
- return false unless $stderr =~ @complaint
+ return false unless @warning =~ @complaint
else
- return false unless $stderr == @complaint
+ return false unless @warning == @complaint
end
end
- return $stderr.empty? ? false : true
- ensure
- $VERBOSE = @verbose
- $stderr = @saved_err
+ return @warning.empty? ? false : true
end
def failure_message
if @complaint.nil?
["Expected a warning", "but received none"]
elsif @complaint.kind_of? Regexp
- ["Expected warning to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
+ ["Expected warning to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"]
else
- ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
+ ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"]
end
end
def negative_failure_message
if @complaint.nil?
- ["Unexpected warning: ", @stderr.chomp.inspect]
+ ["Unexpected warning: ", @warning.chomp.inspect]
elsif @complaint.kind_of? Regexp
- ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
+ ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"]
else
- ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
+ ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"]
end
end
end
diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb
index 28c7a5ea2f..2f9afdc687 100644
--- a/spec/mspec/lib/mspec/matchers/raise_error.rb
+++ b/spec/mspec/lib/mspec/matchers/raise_error.rb
@@ -53,13 +53,19 @@ class RaiseErrorMatcher
exception_class_and_message(exception.class, exception.message)
end
+ def format_result(result)
+ result.pretty_inspect.chomp
+ rescue => e
+ "#pretty_inspect raised #{e.class}; A #<#{result.class}>"
+ end
+
def failure_message
message = ["Expected #{format_expected_exception}"]
if @actual
message << "but got #{format_exception(@actual)}"
else
- message << "but no exception was raised (#{@result.pretty_inspect.chomp} was returned)"
+ message << "but no exception was raised (#{format_result(@result)} was returned)"
end
message
diff --git a/spec/mspec/lib/mspec/runner/context.rb b/spec/mspec/lib/mspec/runner/context.rb
index 2b470f226a..30d8a4ad1b 100644
--- a/spec/mspec/lib/mspec/runner/context.rb
+++ b/spec/mspec/lib/mspec/runner/context.rb
@@ -6,7 +6,7 @@
#--
# A note on naming: this is named _ContextState_ rather
# than _DescribeState_ because +describe+ is the keyword
-# in the DSL for refering to the context in which an example
+# in the DSL for referring to the context in which an example
# is evaluated, just as +it+ refers to the example itself.
#++
class ContextState
diff --git a/spec/mspec/lib/mspec/utils/script.rb b/spec/mspec/lib/mspec/utils/script.rb
index 0c8922c4a8..24cd069bb4 100644
--- a/spec/mspec/lib/mspec/utils/script.rb
+++ b/spec/mspec/lib/mspec/utils/script.rb
@@ -1,4 +1,5 @@
require 'mspec/guards/guard'
+require 'mspec/guards/version'
require 'mspec/utils/warnings'
# MSpecScript provides a skeleton for all the MSpec runner scripts.
@@ -38,7 +39,7 @@ class MSpecScript
end
def initialize
- if RUBY_VERSION < '2.2'
+ ruby_version_is ""..."2.2" do
abort "MSpec needs Ruby 2.2 or more recent"
end
@@ -200,27 +201,30 @@ class MSpecScript
abort "Could not find spec file #{partial}"
end
- # Resolves each entry in +list+ to a set of files.
+ # Resolves each entry in +patterns+ to a set of files.
#
- # If the entry has a leading '^' character, the list of files
+ # If the pattern has a leading '^' character, the list of files
# is subtracted from the list of files accumulated to that point.
#
# If the entry has a leading ':' character, the corresponding
# key is looked up in the config object and the entries in the
# value retrieved are processed through #entries.
- def files(list)
- list.inject([]) do |files, item|
- case item[0]
+ def files(patterns)
+ list = []
+ patterns.each do |pattern|
+ case pattern[0]
when ?^
- files -= entries(item[1..-1])
+ list -= entries(pattern[1..-1])
when ?:
- key = item[1..-1].to_sym
- files += files(Array(config[key]))
+ key = pattern[1..-1].to_sym
+ value = config[key]
+ abort "Key #{pattern} not found in mspec config." unless value
+ list += files(Array(value))
else
- files += entries(item)
+ list += entries(pattern)
end
- files
end
+ list
end
def files_from_patterns(patterns)
@@ -231,12 +235,10 @@ class MSpecScript
if patterns.empty? and File.directory? "./spec"
patterns = ["spec/"]
end
- if patterns.empty?
- puts "No files specified."
- exit 1
- end
end
- files patterns
+ list = files(patterns)
+ abort "No files specified." if list.empty?
+ list
end
def cores(max)
diff --git a/spec/mspec/lib/mspec/utils/warnings.rb b/spec/mspec/lib/mspec/utils/warnings.rb
index ef5e5c692c..4d23474236 100644
--- a/spec/mspec/lib/mspec/utils/warnings.rb
+++ b/spec/mspec/lib/mspec/utils/warnings.rb
@@ -1,6 +1,6 @@
require 'mspec/guards/version'
-if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0"
+if RUBY_ENGINE == "ruby" and ruby_version_is("2.4")
ruby_version_is "2.4"..."2.5" do
# Kernel#warn does not delegate to Warning.warn in 2.4
module Kernel
@@ -16,9 +16,19 @@ if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0"
end
def Warning.warn(message)
+ if Thread.current[:in_mspec_complain_matcher]
+ return $stderr.write(message)
+ end
+
case message
# $VERBOSE = true warnings
- when /possibly useless use of (<|<=|==|>=|>|\+|-) in void context/
+ when /(.+\.rb):(\d+):.+possibly useless use of (<|<=|==|>=|>) in void context/
+ # Make sure there is a .should otherwise it is missing
+ line_nb = Integer($2)
+ unless File.exist?($1) and /\.should(_not)? (<|<=|==|>=|>)/ === File.readlines($1)[line_nb-1]
+ $stderr.write message
+ end
+ when /possibly useless use of (\+|-) in void context/
when /assigned but unused variable/
when /method redefined/
when /previous definition of/