Class: Lookout::Warning

Inherits:
Output show all
Defined in:
lib/lookout-3.0/warning.rb

Overview

Warning expectation proxy. Used to expect warning outputs during the execution of the expect block. Warnings are matched by ignoring any trailing newlines and by removing any file/line warning prefixes. This is done as Ruby internally uses two different functions to generate warnings (rb_warn() and rb_warning()).

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Warning

Proxies the EXPECTED warning output.



11
# File 'lib/lookout-3.0/warning.rb', line 11

def initialize(expected) super expected.chomp end

Instance Method Details

#===(other) ⇒ Object

Returns True if the receiver ‘#==` OTHER or if their classes and normalized expected output `#==` each other.

Returns:

  • True if the receiver ‘#==` OTHER or if their classes and normalized expected output `#==` each other



15
16
17
18
# File 'lib/lookout-3.0/warning.rb', line 15

def ===(other)
  self == other or
    (self.class == other.class and normalized == other.normalized)
end

#diff(other) ⇒ Enumerable<String>

Returns An Enumerable over the formatted operations that would have to be applied to the actual warning output to get the expected warning output after any normalization of the warning outputs have been performed.

Returns:

  • (Enumerable<String>)

    An Enumerable over the formatted operations that would have to be applied to the actual warning output to get the expected warning output after any normalization of the warning outputs have been performed



26
27
28
# File 'lib/lookout-3.0/warning.rb', line 26

def diff(other)
  self == normalized ? super(other.normalized) : normalized.diff(other)
end

#inspectObject



20
# File 'lib/lookout-3.0/warning.rb', line 20

def inspect; 'warning(%p)' % expected end

#to_lookout_expectedExpected::Lookout::Warning

Returns A wrapper around the receiver, making it an expected value.

Returns:



32
# File 'lib/lookout-3.0/warning.rb', line 32

def to_lookout_expected; Lookout::Expected::Lookout::Warning.new(self) end