Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/conformance/rubyspec/FLOOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18790
19008
67 changes: 59 additions & 8 deletions scripts/conformance/rubyspec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ def matches?(actual)
def failure_message; "expected to be close to #{@exp} (+/- #{@tol})"; end
end

class ComplainMatcher
def initialize(*a); end
def matches?(actual); actual.call if actual.respond_to?(:call); true; end
def failure_message; "complain"; end
end

TOLERANCE = 0.00003
# Faithful to real mspec (mspec/lib/mspec/matchers/be_close.rb): a top-level
# (Object) constant, generously large "to account for GC, context switches,
Expand Down Expand Up @@ -112,8 +106,65 @@ def matches?(array)
def failure_message; @bad || "be_computed_by(#{@sym}) mismatch"; end
end
def be_computed_by(sym, *extra); BeComputedByMatcher.new(sym, *extra); end
def complain(*a); raise SpecSkip, "complain matcher unsupported"; end
def output(*a); raise SpecSkip, "output matcher unsupported"; end
# complain: the block should (or should_not) write a warning to $stderr. An
# optional String (exact) or Regexp (match) constrains the warning text; the
# verbose: keyword runs the block under that $VERBOSE. Mirrors mspec's
# ComplainMatcher (mspec/lib/mspec/matchers/complain.rb).
class ComplainMatcher
def initialize(pat, verbose); @pat, @verbose = pat, verbose; end
def matches?(callable)
require "stringio"
old_err, $stderr = $stderr, StringIO.new
# mspec runs the block under $VERBOSE = false by default, or the given
# verbose: value; it never leaves the ambient level in place.
old_v = $VERBOSE
$VERBOSE = @verbose.nil? ? false : @verbose
begin
callable.call
ensure
$VERBOSE = old_v
out = $stderr.string
$stderr = old_err
end
# A constraining pattern must match, but a warning is still required: mspec
# ends on `warning.empty? ? false : true` even after a successful match.
unless @pat.nil?
if @pat.is_a?(Regexp)
return false unless out =~ @pat
else
return false unless out == @pat
end
end
!out.empty?
end
def failure_message; "expected a warning#{@pat ? " matching #{@pat.inspect}" : ''}"; end
end
def complain(pat = nil, verbose: nil); ComplainMatcher.new(pat, verbose); end

# output: capture $stdout (and, with a second argument, $stderr) around the block
# and match each against a String (exact) or Regexp. Mirrors mspec's
# OutputMatcher. output_to_fd (real fd redirection) stays unsupported.
class OutputMatcher
def initialize(out, err); @out, @err = out, err; end
def matches?(callable)
require "stringio"
oo, $stdout = $stdout, StringIO.new
oe, $stderr = $stderr, StringIO.new
begin
callable.call
ensure
so, se = $stdout.string, $stderr.string
$stdout, $stderr = oo, oe
end
ok = true
ok &&= match_stream(@out, so) unless @out.nil?
ok &&= match_stream(@err, se) unless @err.nil?
ok
end
def match_stream(pat, s); pat.is_a?(Regexp) ? !!(s =~ pat) : (s == pat); end
def failure_message; "output did not match"; end
end
def output(out = nil, err = nil); OutputMatcher.new(out, err); end
def output_to_fd(*a); raise SpecSkip, "output_to_fd matcher unsupported"; end

class RaiseMatcher
Expand Down