Class: Clowne::RSpec::Matchers::CloneAssociation

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Includes:
Helpers
Defined in:
lib/clowne/rspec/clone_association.rb

Constant Summary collapse

AVAILABLE_PARAMS =
%i[
  traits
  clone_with
  params
  scope
].freeze

Instance Attribute Summary collapse

Attributes included from Helpers

#cloner

Instance Method Summary collapse

Methods included from Helpers

#matches?, #non_cloner_message, #plan, #with_traits

Constructor Details

#initialize(name, options) ⇒ CloneAssociation

Returns a new instance of CloneAssociation.



18
19
20
21
# File 'lib/clowne/rspec/clone_association.rb', line 18

def initialize(name, options)
  @expected = name
  extract_options! options
end

Instance Attribute Details

#expected_paramsObject (readonly)

Returns the value of attribute expected_params.



16
17
18
# File 'lib/clowne/rspec/clone_association.rb', line 16

def expected_params
  @expected_params
end

Instance Method Details

#does_not_match?Boolean

rubocop: enable Metrics/AbcSize

Returns:

  • (Boolean)


41
42
43
# File 'lib/clowne/rspec/clone_association.rb', line 41

def does_not_match?(*)
  raise "This matcher doesn't support negation"
end

#failure_messageObject



45
46
47
48
49
50
51
# File 'lib/clowne/rspec/clone_association.rb', line 45

def failure_message
  if @actual.nil?
    "expected to include association #{expected}, but none found"
  else
    params_failure_message
  end
end

#match(expected, _actual) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clowne/rspec/clone_association.rb', line 23

def match(expected, _actual)
  @actual = plan.declarations
    .find { |key, decl| key == :association && decl.name == expected }

  return false if @actual.nil?

  @actual = actual.last

  AVAILABLE_PARAMS.each do |param|
    if expected_params[param] != UNDEFINED
      return false if expected_params[param] != actual.send(param)
    end
  end

  true
end