Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::HaveAttrWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb

Overview

TODO: Specs.

Instance Method Summary collapse

Constructor Details

#initialize(attr_name) ⇒ HaveAttrWriter

Returns a new instance of HaveAttrWriter.



11
12
13
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb', line 11

def initialize(attr_name)
  @attr_name = attr_name
end

Instance Method Details

#descriptionObject



28
29
30
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb', line 28

def description
  "have attr writer `#{attr_name}`"
end

#failure_messageObject



32
33
34
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb', line 32

def failure_message
  "expected `#{object.class}` to have attr writer `#{attr_name}`"
end

#failure_message_when_negatedObject



36
37
38
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb', line 36

def failure_message_when_negated
  "expected `#{object.class}` NOT to have attr writer `#{attr_name}`"
end

#matches?(object) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_attr_writer.rb', line 15

def matches?(object)
  @object = object

  ##
  # IMPORTANT: A copy is created in order to be thread safe.
  #
  copy = object.dup

  copy.public_send("#{attr_name}=", :custom_value)

  copy.instance_variable_get("@#{attr_name}") == :custom_value
end