Class: Minicrest::InstanceOf

Inherits:
Matcher
  • Object
show all
Defined in:
lib/minicrest/value_matchers.rb

Overview

Matcher that checks for exact class membership.

Instance Method Summary collapse

Methods inherited from Matcher

#&, #|

Constructor Details

#initialize(expected_type) ⇒ InstanceOf

Returns a new instance of InstanceOf.



65
66
67
68
# File 'lib/minicrest/value_matchers.rb', line 65

def initialize(expected_type)
  super()
  @expected_type = expected_type
end

Instance Method Details

#descriptionObject



74
75
76
# File 'lib/minicrest/value_matchers.rb', line 74

def description
  "an instance of #{@expected_type}"
end

#failure_message(actual) ⇒ Object



78
79
80
# File 'lib/minicrest/value_matchers.rb', line 78

def failure_message(actual)
  "expected #{actual.inspect} to be an instance of #{@expected_type}, but was a #{actual.class}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/minicrest/value_matchers.rb', line 70

def matches?(actual)
  actual.instance_of?(@expected_type)
end

#negated_failure_message(actual) ⇒ Object



82
83
84
# File 'lib/minicrest/value_matchers.rb', line 82

def negated_failure_message(actual)
  "expected #{actual.inspect} not to be an instance of #{@expected_type}, but it was"
end