Class: Expected::Matchers::HaveAttrAccessorMatcher

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

Overview

Class used by #have_constant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveAttrAccessorMatcher

Returns a new instance of HaveAttrAccessorMatcher.

Parameters:

  • attribute (String, Symbol)

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



27
28
29
30
31
32
33
34
# File 'lib/expected/matchers/have_attr_accessor.rb', line 27

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

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



24
25
26
# File 'lib/expected/matchers/have_attr_accessor.rb', line 24

def attribute
  @attribute
end

#has_attr_readerObject (readonly)

Returns the value of attribute has_attr_reader.



24
25
26
# File 'lib/expected/matchers/have_attr_accessor.rb', line 24

def has_attr_reader
  @has_attr_reader
end

#has_attr_writerObject (readonly)

Returns the value of attribute has_attr_writer.



24
25
26
# File 'lib/expected/matchers/have_attr_accessor.rb', line 24

def has_attr_writer
  @has_attr_writer
end

#subjectObject

Returns the value of attribute subject.



24
25
26
# File 'lib/expected/matchers/have_attr_accessor.rb', line 24

def subject
  @subject
end

Instance Method Details

#descriptionString

Returns:

  • (String)


56
57
58
# File 'lib/expected/matchers/have_attr_accessor.rb', line 56

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

#failure_messageString

Returns:

  • (String)


46
47
48
# File 'lib/expected/matchers/have_attr_accessor.rb', line 46

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

#failure_message_when_negatedString

Returns:

  • (String)


51
52
53
# File 'lib/expected/matchers/have_attr_accessor.rb', line 51

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



40
41
42
43
# File 'lib/expected/matchers/have_attr_accessor.rb', line 40

def matches?(subject)
  self.subject = subject
  matches_attr_reader? && matches_attr_writer?
end