Sha256: a3420873b3a91799499bc953cd7f92b85692b39012dc54953df5b81bff60a725

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

require "pact_broker/hash_refinements"

module PactBroker
  describe HashRefinements do
    using HashRefinements

    let(:a) { { a: 1, b: { c: 3 }, d: 5, e: nil } }
    let(:b) { { a: 2, b: { c: 4 } } }
    let(:expected) { { a: 2, b: { c: 4 }, d: 5, e: nil } }

    it "merges" do
      expect(a.deep_merge(b)).to eq expected
    end

    describe "camelcase_keys" do
      let(:hash_1) do
        {
          "foo_bar" => {
            :meep_moop => "blahBlah",
            "beepBoop" => ""
          }
        }
      end

      let(:expected) do
        {
          "fooBar" => {
            :meepMoop => "blahBlah",
            "beepBoop" => ""
          }
        }
      end

      it "camel cases the keys" do
        expect(hash_1.camelcase_keys).to eq expected
      end
    end

    describe "snakecase_keys" do
      let(:hash_1) do
        {
          "fooBar" => {
            :meepMoop => "blahBlah",
            "already_snake" => ""
          }
        }
      end

      let(:expected) do
        {
          "foo_bar" => {
            :meep_moop => "blahBlah",
            "already_snake" => ""
          }
        }
      end

      it "snake cases the keys" do
        expect(hash_1.snakecase_keys).to eq expected
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.89.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.88.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.87.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.86.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.85.1 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.85.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.84.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.83.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.82.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.81.0 spec/lib/pact_broker/hash_refinements_spec.rb
pact_broker-2.80.0 spec/lib/pact_broker/hash_refinements_spec.rb