Class: Clowne::RSpec::Matchers::CloneAssociation
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Clowne::RSpec::Matchers::CloneAssociation
- 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
-
#expected_params ⇒ Object
readonly
Returns the value of attribute expected_params.
Attributes included from Helpers
Instance Method Summary collapse
-
#does_not_match? ⇒ Boolean
rubocop: enable Metrics/AbcSize.
- #failure_message ⇒ Object
-
#initialize(name, options) ⇒ CloneAssociation
constructor
A new instance of CloneAssociation.
- #match(expected, _actual) ⇒ Object
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, ) @expected = name end |
Instance Attribute Details
#expected_params ⇒ Object (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
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_message ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/clowne/rspec/clone_association.rb', line 45 def if @actual.nil? "expected to include association #{expected}, but none found" else 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 |