Class: Lookout::Expected::Symbol

Inherits:
Object show all
Defined in:
lib/lookout-3.0/expected/symbol.rb

Overview

Represents expected Symbols. A Symbol that’s suffixed by “?” is considered to be a query to be invoked on the actual result. If such a symbol is prefixed by “not_”, the result of the query is inversed.

Instance Method Summary collapse

Methods inherited from Object

#expect

Constructor Details

#initialize(expected) ⇒ Symbol

Returns a new instance of Symbol.



7
8
9
10
# File 'lib/lookout-3.0/expected/symbol.rb', line 7

def initialize(expected)
  super
  @negated, @query = /\A(?:(not)_)?(?:(.+\?)|.*)\z/m.match(expected.to_s)[1..2]
end

Instance Method Details

#difference(actual) ⇒ Difference::Symbol?

Returns A difference report between actual and #expected if #expected is a query and the result of the query doesn’t equal what’s expected, super otherwise.

Parameters:

Returns:

  • (Difference::Symbol, nil)

    A difference report between actual and #expected if #expected is a query and the result of the query doesn’t equal what’s expected, super otherwise



16
17
18
19
20
# File 'lib/lookout-3.0/expected/symbol.rb', line 16

def difference(actual)
  return super if not @query or Symbol === actual or actual.method(@query).arity != 0
  Lookout::Difference::Symbol.new(actual, expected, @query, @negated) unless
    (not not actual.send(@query)) ^ !!@negated
end