Class: Expected::Matchers::HaveAttrWriterMatcher

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

Overview

Class used by #have_constant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveAttrWriterMatcher

Returns a new instance of HaveAttrWriterMatcher.

Parameters:

  • attribute (String, Symbol)

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



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

def initialize(attribute)
  unless attribute.is_a?(String) || attribute.is_a?(Symbol)
    raise 'HaveAttrWriterMatcher 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_writer.rb', line 22

def attribute
  @attribute
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

Instance Method Details

#descriptionString

Returns:

  • (String)


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

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

#failure_messageString

Returns:

  • (String)


43
44
45
# File 'lib/expected/matchers/have_attr_writer.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_writer.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_writer.rb', line 36

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