class Expected::Matchers::HaveAttrAccessorMatcher
Class used by {#have_constant}
Attributes
attribute[R]
has_attr_reader[R]
has_attr_writer[R]
subject[R]
Public Class Methods
new(attribute)
click to toggle source
@param attribute [String, Symbol] The attribute the {#subject} is expected to have an attr_accessor for
# 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
Public Instance Methods
description()
click to toggle source
@return [String]
# File lib/expected/matchers/have_attr_accessor.rb, line 56 def description "have_attr_accessor: `#{attribute}`" end
failure_message()
click to toggle source
@return [String]
# File lib/expected/matchers/have_attr_accessor.rb, line 46 def failure_message "Expected #{expectation} (#{@failure})" end
failure_message_when_negated()
click to toggle source
@return [String]
# File lib/expected/matchers/have_attr_accessor.rb, line 51 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/have_attr_accessor.rb, line 40 def matches?(subject) self.subject = subject matches_attr_reader? && matches_attr_writer? end
Private Instance Methods
expectation()
click to toggle source
@return String
# File lib/expected/matchers/have_attr_accessor.rb, line 83 def expectation "<#{subject}> to have attr_accessor `#{attribute}`" end
matches_attr_reader?()
click to toggle source
# File lib/expected/matchers/have_attr_accessor.rb, line 68 def matches_attr_reader? ret = has_attr_reader.matches?(subject) msg = has_attr_reader.instance_variable_get(:@failure) @failure = msg if msg ret end
matches_attr_writer?()
click to toggle source
# File lib/expected/matchers/have_attr_accessor.rb, line 75 def matches_attr_writer? ret = has_attr_writer.matches?(subject) msg = has_attr_writer.instance_variable_get(:@failure) @failure = msg if msg ret end
subject=(subject)
click to toggle source
The thing to test against @return [Class, Module]
# File lib/expected/matchers/have_attr_accessor.rb, line 64 def subject=(subject) # rubocop:disable Style/TrivialAccessors @subject = subject end