Sha256: ad8f9ab6c0a568aa45c0e15e339bfdbf2f64f1a8df3058511125d4a66529c77b

Contents?: true

Size: 1.9 KB

Versions: 69

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

module WebMock
  module Matchers
    describe HashExcludingMatcher do
      it 'stringifies the given hash keys' do
        expect(HashExcludingMatcher.new(a: 1, b: 2)).not_to eq('a' => 1, 'b' => 2)
      end

      it 'sorts elements in the hash' do
        expect(HashExcludingMatcher.new(b: 2, a: 1)).not_to eq('a' => 1, 'b' => 2)
      end

      it 'describes itself properly' do
        expect(HashExcludingMatcher.new(a: 1).inspect).to eq 'hash_excluding({"a"=>1})'
      end

      describe 'success' do
        it 'match with hash with a missing key' do
          expect(HashExcludingMatcher.new(a: 1)).to eq('b' => 2)
        end

        it 'match an empty hash with a given key' do
          expect(HashExcludingMatcher.new(a: 1)).to eq({})
        end

        it 'match when values are nil but keys are different' do
          expect(HashExcludingMatcher.new(a: nil)).to eq('b' => nil)
        end

        describe 'when matching an empty hash' do
          it 'does not matches against any hash' do
            expect(HashExcludingMatcher.new({})).to eq(a: 1, b: 2, c: 3)
          end
        end
      end

      describe 'failing' do
        it 'does not match a hash with a one missing key when one pair is matching' do
          expect(HashExcludingMatcher.new(a: 1, b: 2)).not_to eq('b' => 2)
        end

        it 'match a hash with an incorrect value' do
          expect(HashExcludingMatcher.new(a: 1, b: 2)).not_to eq('a' => 1, 'b' => 3)
        end

        it 'does not matches the same hash' do
          expect(HashExcludingMatcher.new('a' => 1, 'b' => 2)).not_to eq('a' => 1, 'b' => 2)
        end

        it 'does not matches a hash with extra stuff' do
          expect(HashExcludingMatcher.new(a: 1)).not_to eq('a' => 1, 'b' => 2)
        end

        it 'does not match a non-hash' do
          expect(HashExcludingMatcher.new(a: 1)).not_to eq 1
        end
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 5 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/webmock-3.18.1/spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.18.1 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.18.0 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.15.2 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.16.2 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.16.1 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.15.1 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.17.1 spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.17.0 spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/unit/matchers/hash_excluding_matcher_spec.rb
webmock-3.14.0 spec/unit/matchers/hash_excluding_matcher_spec.rb