mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/mspec@215497e
This commit is contained in:
parent
4fcc7e2d7c
commit
6ae81d49b5
4 changed files with 48 additions and 13 deletions
|
@ -32,4 +32,8 @@ class SpecExpectation
|
|||
result_to_s = MSpec.format(result)
|
||||
raise SpecExpectationNotMetError, "Expected #{receiver_to_s}#{predicate_to_s}#{args_to_s}\n#{expectation} but was #{result_to_s}"
|
||||
end
|
||||
|
||||
def self.fail_single_arg_predicate(receiver, predicate, arg, result, expectation)
|
||||
fail_predicate(receiver, predicate, [arg], nil, result, expectation)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,15 +16,24 @@ class SpecPositiveOperatorMatcher < BasicObject
|
|||
end
|
||||
|
||||
def ==(expected)
|
||||
method_missing(:==, expected)
|
||||
result = @actual == expected
|
||||
unless result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :==, expected, result, "to be truthy")
|
||||
end
|
||||
end
|
||||
|
||||
def !=(expected)
|
||||
method_missing(:!=, expected)
|
||||
result = @actual != expected
|
||||
unless result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :!=, expected, result, "to be truthy")
|
||||
end
|
||||
end
|
||||
|
||||
def equal?(expected)
|
||||
method_missing(:equal?, expected)
|
||||
result = @actual.equal?(expected)
|
||||
unless result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :equal?, expected, result, "to be truthy")
|
||||
end
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
|
@ -41,15 +50,24 @@ class SpecNegativeOperatorMatcher < BasicObject
|
|||
end
|
||||
|
||||
def ==(expected)
|
||||
method_missing(:==, expected)
|
||||
result = @actual == expected
|
||||
if result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :==, expected, result, "to be falsy")
|
||||
end
|
||||
end
|
||||
|
||||
def !=(expected)
|
||||
method_missing(:!=, expected)
|
||||
result = @actual != expected
|
||||
if result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :!=, expected, result, "to be falsy")
|
||||
end
|
||||
end
|
||||
|
||||
def equal?(expected)
|
||||
method_missing(:equal?, expected)
|
||||
result = @actual.equal?(expected)
|
||||
if result
|
||||
::SpecExpectation.fail_single_arg_predicate(@actual, :equal?, expected, result, "to be falsy")
|
||||
end
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
|
|
|
@ -42,12 +42,12 @@ class OutputMatcher
|
|||
expected_out = "\n"
|
||||
actual_out = "\n"
|
||||
unless @out.nil?
|
||||
expected_out += " $stdout: #{@out.inspect}\n"
|
||||
actual_out += " $stdout: #{@stdout.inspect}\n"
|
||||
expected_out += " $stdout: #{MSpec.format(@out)}\n"
|
||||
actual_out += " $stdout: #{MSpec.format(@stdout.to_s)}\n"
|
||||
end
|
||||
unless @err.nil?
|
||||
expected_out += " $stderr: #{@err.inspect}\n"
|
||||
actual_out += " $stderr: #{@stderr.inspect}\n"
|
||||
expected_out += " $stderr: #{MSpec.format(@err)}\n"
|
||||
actual_out += " $stderr: #{MSpec.format(@stderr.to_s)}\n"
|
||||
end
|
||||
["Expected:#{expected_out}", " got:#{actual_out}"]
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ class TimeoutAction
|
|||
def register
|
||||
MSpec.register :start, self
|
||||
MSpec.register :before, self
|
||||
MSpec.register :after, self
|
||||
MSpec.register :finish, self
|
||||
end
|
||||
|
||||
|
@ -35,8 +36,12 @@ class TimeoutAction
|
|||
if @queue.empty?
|
||||
elapsed = now - @started
|
||||
if elapsed > @timeout
|
||||
STDERR.puts "\n#{@current_state.description}"
|
||||
STDERR.puts "Example took longer than the configured timeout of #{@timeout}s"
|
||||
if @current_state
|
||||
STDERR.puts "\nExample took longer than the configured timeout of #{@timeout}s:"
|
||||
STDERR.puts "#{@current_state.description}"
|
||||
else
|
||||
STDERR.puts "\nSome code outside an example took longer than the configured timeout of #{@timeout}s"
|
||||
end
|
||||
STDERR.flush
|
||||
|
||||
show_backtraces
|
||||
|
@ -56,6 +61,12 @@ class TimeoutAction
|
|||
end
|
||||
end
|
||||
|
||||
def after(state = nil)
|
||||
@queue << -> do
|
||||
@current_state = nil
|
||||
end
|
||||
end
|
||||
|
||||
def finish
|
||||
@thread.kill
|
||||
@thread.join
|
||||
|
@ -73,7 +84,9 @@ class TimeoutAction
|
|||
Truffle::Debug.show_backtraces
|
||||
else
|
||||
Thread.list.each do |thread|
|
||||
STDERR.puts thread.inspect, thread.backtrace, ''
|
||||
unless thread == Thread.current
|
||||
STDERR.puts thread.inspect, thread.backtrace, ''
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue