Module: Servactory::TestKit::Rspec::Matchers::Concerns::ValueComparison::InstanceMethods
- Defined in:
- lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb
Overview
Instance methods added by this concern.
Instance Method Summary collapse
-
#arrays_match?(expected, actual) ⇒ Boolean
Compares two arrays element-by-element.
-
#types_match?(expected_types, actual_types) ⇒ Boolean
Compares two type collections for equality (order-independent).
-
#values_match?(expected, actual) ⇒ Boolean
Compares expected and actual values with type-aware logic.
Instance Method Details
#arrays_match?(expected, actual) ⇒ Boolean
Compares two arrays element-by-element.
75 76 77 78 79 |
# File 'lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb', line 75 def arrays_match?(expected, actual) return false unless expected.size == actual.size expected.zip(actual).all? { |e, a| values_match?(e, a) } end |
#types_match?(expected_types, actual_types) ⇒ Boolean
Compares two type collections for equality (order-independent).
86 87 88 89 90 |
# File 'lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb', line 86 def types_match?(expected_types, actual_types) expected_set = Set.new(expected_types) actual_set = Set.new(actual_types) expected_set == actual_set end |
#values_match?(expected, actual) ⇒ Boolean
Compares expected and actual values with type-aware logic.
Supports:
-
RSpec matchers (anything responding to :matches?)
-
Class comparison (type checking with is_a?)
-
Array comparison (recursive element-wise)
-
Standard equality (==)
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb', line 58 def values_match?(expected, actual) if expected.respond_to?(:matches?) expected.matches?(actual) elsif expected.is_a?(Class) actual.is_a?(expected) elsif expected.is_a?(Array) && actual.is_a?(Array) arrays_match?(expected, actual) else expected == actual end end |