Class: Expected::Matchers::HaveAttrReaderMatcher

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

Overview

Class used by #have_constant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveAttrReaderMatcher

Returns a new instance of HaveAttrReaderMatcher.

Parameters:

  • attribute (String, Symbol)

    The attribute the #subject is expected to have an attr_reader for



25
26
27
28
29
30
# File 'lib/expected/matchers/have_attr_reader.rb', line 25

def initialize(attribute)
  unless attribute.is_a?(String) || attribute.is_a?(Symbol)
    raise 'HaveAttrReaderMatcher attribute must be a String or Symbol'
  end
  @attribute = attribute.to_sym
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



22
23
24
# File 'lib/expected/matchers/have_attr_reader.rb', line 22

def attribute
  @attribute
end

#subjectObject

Returns the value of attribute subject.



22
23
24
# File 'lib/expected/matchers/have_attr_reader.rb', line 22

def subject
  @subject
end

Instance Method Details

#descriptionString

Returns:

  • (String)


53
54
55
# File 'lib/expected/matchers/have_attr_reader.rb', line 53

def description
  "have_attr_reader: `#{attribute}`"
end

#failure_messageString

Returns:

  • (String)


43
44
45
# File 'lib/expected/matchers/have_attr_reader.rb', line 43

def failure_message
  "Expected #{expectation} (#{@failure})"
end

#failure_message_when_negatedString

Returns:

  • (String)


48
49
50
# File 'lib/expected/matchers/have_attr_reader.rb', line 48

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



36
37
38
39
40
# File 'lib/expected/matchers/have_attr_reader.rb', line 36

def matches?(subject)
  self.subject = subject
  method? &&
    returns_correct_value?
end