module MiniSpec::ThrowInspector

Public Instance Methods

any_symbol_thrown?(thrown_symbol, context) click to toggle source
# File lib/minispec/utils/throw.rb, line 90
def any_symbol_thrown? thrown_symbol, context
  if context[:negation]
    return true if !thrown_symbol
    return ThrowError.new('%s symbol thrown when not expected' % pp(thrown_symbol))
  end
  return true if thrown_symbol
  ThrowError.new('Expected a symbol to be thrown')
end
correct_symbol_thrown?(expected_symbol, thrown_symbol, context) click to toggle source
# File lib/minispec/utils/throw.rb, line 99
def correct_symbol_thrown? expected_symbol, thrown_symbol, context
  # needed here cause this method are invoked directly by mock validators.
  # and it's not a double check cause Utils.symbol_thrown?
  # wont arrive here if called with a block
  if context[:right_proc]
    return thrown_as_expected_by_proc?(thrown_symbol, context)
  end

  x = expected_symbol == thrown_symbol
  if context[:negation]
    return true if !x
    return ThrowError.new('Not expected %s symbol to be thrown' % pp(thrown_symbol))
  end
  return true if x
  ThrowError.new('Expected %s symbol to be thrown. Instead %s thrown.' % [
    pp(expected_symbol),
    thrown_symbol ?
      pp(thrown_symbol) :
      'nothing'
  ])
end
correct_value_thrown?(thrown_symbol, expected_value, thrown_value, context) click to toggle source
# File lib/minispec/utils/throw.rb, line 121
def correct_value_thrown? thrown_symbol, expected_value, thrown_value, context
  x = expected_value.is_a?(Regexp)   ?
    (thrown_value.to_s =~ expected_value) :
    (thrown_value      == expected_value)
  if context[:negation]
    return true if !x
    return ThrowError.new('Not expected %s symbol\'s value to match %s' % [
      thrown_symbol,
      thrown_value,
    ].map(&method(:pp)))
  end
  return true if x
  ThrowError.new("Expected %s symbol's value to match %s\nActual value: %s" % [
    thrown_symbol,
    expected_value,
    thrown_value
  ].map(&method(:pp)))
end
thrown_as_expected?(expected_symbol, expected_value, thrown_symbol, thrown_value, context) click to toggle source
# File lib/minispec/utils/throw.rb, line 78
def thrown_as_expected? expected_symbol, expected_value, thrown_symbol, thrown_value, context
  if expected_symbol && expected_value
    x = correct_symbol_thrown?(expected_symbol, thrown_symbol, context)
    return x if x.is_a?(ThrowError)
    correct_value_thrown?(expected_symbol, expected_value, thrown_value, context)
  elsif expected_symbol
    correct_symbol_thrown?(expected_symbol, thrown_symbol, context)
  else
    any_symbol_thrown?(thrown_symbol, context)
  end
end
thrown_as_expected_by_proc?(thrown_symbol, context) click to toggle source
# File lib/minispec/utils/throw.rb, line 68
def thrown_as_expected_by_proc? thrown_symbol, context
  x = context[:right_proc].call(*thrown_symbol) # splat needed on multiple expectations
  if context[:negation]
    return true if !x
    return ThrowError.new('Not expected any symbol to be thrown')
  end
  return true if x
  ThrowError.new('Expected a symbol to be thrown')
end