Sha256: 34965d2d31409646d195791d8310e77657b9c0521142e0bfa16c344fd459058e

Contents?: true

Size: 750 Bytes

Versions: 57

Compression:

Stored size: 750 Bytes

Contents

module Matchers; module Include
  extend RSpec::Matchers::DSL

  matcher :include_in_any_order do |*matchers|
    match do |enumerable|
      @not_matched = []
      expected.each do |matcher|
        if enumerable.empty?
          break
        end

        if found = enumerable.find { |elem| matcher.matches?(elem) }
          enumerable = enumerable.reject { |elem| elem == found }
        else
          @not_matched << matcher
        end
      end


      @not_matched.empty? && enumerable.empty?
    end

    failure_message_for_should do |enumerable|
      "did not match #{@not_matched.collect(&:description).join(', ')} in #{enumerable.inspect}: <#{@not_matched.collect(&:failure_message_for_should).join('>, <')}>"
    end
  end
end; end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
puppet-3.8.1-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.5 spec/lib/matchers/include.rb
puppet-3.7.5-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.5-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.4 spec/lib/matchers/include.rb
puppet-3.7.4-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.4-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.3 spec/lib/matchers/include.rb
puppet-3.7.3-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.3-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.2 spec/lib/matchers/include.rb
puppet-3.7.2-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.2-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.1 spec/lib/matchers/include.rb
puppet-3.7.1-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.1-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.7.0 spec/lib/matchers/include.rb
puppet-3.7.0-x86-mingw32 spec/lib/matchers/include.rb
puppet-3.7.0-x64-mingw32 spec/lib/matchers/include.rb
puppet-3.6.2 spec/lib/matchers/include.rb