Class: Expected::Matchers::InheritFromMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/expected/matchers/inherit_from.rb

Overview

Class used by #inherit_from

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_ancestor) ⇒ InheritFromMatcher

Returns a new instance of InheritFromMatcher.

Parameters:

  • expected_ancestor (Class)

    The ancestor the #subject is expected to inherit from



23
24
25
# File 'lib/expected/matchers/inherit_from.rb', line 23

def initialize(expected_ancestor)
  @expected_ancestor = expected_ancestor
end

Instance Attribute Details

#expected_ancestorObject (readonly)

Returns the value of attribute expected_ancestor.



20
21
22
# File 'lib/expected/matchers/inherit_from.rb', line 20

def expected_ancestor
  @expected_ancestor
end

#subjectObject

Returns the value of attribute subject.



20
21
22
# File 'lib/expected/matchers/inherit_from.rb', line 20

def subject
  @subject
end

Instance Method Details

#descriptionString

Returns:

  • (String)


47
48
49
# File 'lib/expected/matchers/inherit_from.rb', line 47

def description
  "inherit_from: <#{expected_ancestor.inspect}>"
end

#failure_messageString

Returns:

  • (String)


37
38
39
# File 'lib/expected/matchers/inherit_from.rb', line 37

def failure_message
  "Expected #{expectation}"
end

#failure_message_when_negatedString

Returns:

  • (String)


42
43
44
# File 'lib/expected/matchers/inherit_from.rb', line 42

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#matches?(subject) ⇒ True, False

Run the test

Parameters:

  • subject

    The thing to test against

Returns:

  • (True)

    If the test passes

  • (False)

    if the test fails



31
32
33
34
# File 'lib/expected/matchers/inherit_from.rb', line 31

def matches?(subject)
  self.subject = subject
  self.subject.ancestors.include? expected_ancestor
end