class Expected::Matchers::InheritFromMatcher

Class used by {#inherit_from}

Attributes

expected_ancestor[R]
subject[R]

Public Class Methods

new(expected_ancestor) click to toggle source

@param expected_ancestor [Class] The ancestor the {#subject} is expected to inherit from

# File lib/expected/matchers/inherit_from.rb, line 23
def initialize(expected_ancestor)
  @expected_ancestor = expected_ancestor
end

Public Instance Methods

description() click to toggle source

@return [String]

# File lib/expected/matchers/inherit_from.rb, line 47
def description
  "inherit_from: <#{expected_ancestor.inspect}>"
end
failure_message() click to toggle source

@return [String]

# File lib/expected/matchers/inherit_from.rb, line 37
def failure_message
  "Expected #{expectation}"
end
failure_message_when_negated() click to toggle source

@return [String]

# File lib/expected/matchers/inherit_from.rb, line 42
def failure_message_when_negated
  "Did not expect #{expectation}"
end
matches?(subject) click to toggle source

Run the test @param subject The thing to test against @return [True] If the test passes @return [False] if the test fails

# File lib/expected/matchers/inherit_from.rb, line 31
def matches?(subject)
  self.subject = subject
  self.subject.ancestors.include? expected_ancestor
end

Private Instance Methods

expectation() click to toggle source

@return String

# File lib/expected/matchers/inherit_from.rb, line 60
def expectation
  "<#{subject.inspect}> to inherit from <#{expected_ancestor.inspect}>"
end
subject=(subject) click to toggle source

The thing to test against @return [Class, Module]

# File lib/expected/matchers/inherit_from.rb, line 55
def subject=(subject)
  @subject = subject.instance_of?(Class) || subject.is_a?(Module) ? subject : subject.class
end