Class: BaconExpect::Matcher::MatchArray
- Inherits:
-
Object
- Object
- BaconExpect::Matcher::MatchArray
- Defined in:
- lib/bacon-expect/matchers/match_array.rb
Instance Method Summary collapse
- #fail!(subject_array, negated) ⇒ Object
-
#initialize(expected_array) ⇒ MatchArray
constructor
A new instance of MatchArray.
- #matches?(subject_array) ⇒ Boolean
Constructor Details
#initialize(expected_array) ⇒ MatchArray
Returns a new instance of MatchArray.
3 4 5 |
# File 'lib/bacon-expect/matchers/match_array.rb', line 3 def initialize(expected_array) @expected_array = expected_array end |
Instance Method Details
#fail!(subject_array, negated) ⇒ Object
17 18 19 |
# File 'lib/bacon-expect/matchers/match_array.rb', line 17 def fail!(subject_array, negated) raise FailedExpectation.new(FailMessageRenderer.(negated, subject_array, @expected_array)) end |
#matches?(subject_array) ⇒ Boolean
7 8 9 10 11 12 13 14 15 |
# File 'lib/bacon-expect/matchers/match_array.rb', line 7 def matches?(subject_array) return false unless subject_array.size == @expected_array.size array_copy = subject_array.dup @expected_array.all? do |item| has = array_copy.include?(item) array_copy.delete(item) if has has end end |