Class: DynportTools::HaveAttributesMatcher::HaveAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/dynport_tools/have_attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveAttributes

Returns a new instance of HaveAttributes.



3
4
5
# File 'lib/dynport_tools/have_attributes.rb', line 3

def initialize(expected)
  @expected = expected
end

Instance Method Details

#differObject



7
8
9
# File 'lib/dynport_tools/have_attributes.rb', line 7

def differ
  @differ ||= DynportTools::Differ.new(:diff_all => false)
end

#failure_messageObject



26
27
28
# File 'lib/dynport_tools/have_attributes.rb', line 26

def failure_message
  @error
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dynport_tools/have_attributes.rb', line 11

def matches?(target)
  @target = if target.respond_to?(:attributes)
    differ.symbolize_keys = true
    target.attributes
  else
    target
  end
  if diff = differ.diff(@expected, @target)
    @error = differ.diff_to_message_lines(diff).join("\n")
    false
  else
    true
  end
end