Sha256: 2f6bb7c39da851512e8c626f6defe749990843babd539761aa97c66c85f56ae1

Contents?: true

Size: 780 Bytes

Versions: 10

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

require "spec_helper"

module Trailblazer
  class Finder
    module Utils
      describe Hash do
        let(:hash) do
          [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: ""}, {id: 4, value: "Test 4"}]
        end

        describe ".deep_locate" do
          it "locates enumerables for which the given comparator returns true for at least one element" do
            expect(described_class.deep_locate(->(k, v, _) { k == :value && v.to_s == "Test 2" && !v.nil? }, hash))
              .to eq [{id: 2, value: "Test 2"}]
          end
        end

        it "returns an empty array if nothing was found" do
          expect(described_class.deep_locate(:muff, foo: "bar")).to eq([])
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
trailblazer-finder-0.70.0 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.50.0 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.10.3 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.10.2 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.10.1 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.10.0 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.3.0 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.2.7 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.2.6 spec/trailblazer/finder/utils/hash_spec.rb
trailblazer-finder-0.2.5 spec/trailblazer/finder/utils/hash_spec.rb