Class: Plyushkin::Test::PersistedAttributeMatcher

Inherits:
MatcherBase
  • Object
show all
Defined in:
lib/plyushkin/test/persisted_attribute_matcher.rb

Defined Under Namespace

Classes: WithFormatMatcher

Instance Method Summary collapse

Methods inherited from MatcherBase

#description, #failure_message, #matchers, #negative_failure_message

Constructor Details

#initialize(attr_name) ⇒ PersistedAttributeMatcher

Returns a new instance of PersistedAttributeMatcher.



3
4
5
# File 'lib/plyushkin/test/persisted_attribute_matcher.rb', line 3

def initialize(attr_name)
  @attr_name = attr_name
end

Instance Method Details

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/plyushkin/test/persisted_attribute_matcher.rb', line 12

def matches?(subject)
  @failure_message          = "Plyushkin: no persisted attribute with name '#{@attr_name}'" unless subject.class.persisted_attributes.include?(@attr_name)
  @negative_failure_message = "Plyushkin: persisted attribute with name '#{@attr_name}' exists" unless subject.class.persisted_attributes.include?(@attr_name)
  super
end

#with_format(formatter) ⇒ Object



7
8
9
10
# File 'lib/plyushkin/test/persisted_attribute_matcher.rb', line 7

def with_format(formatter)
  matchers << WithFormatMatcher.new(@attr_name, formatter)
  self
end