Sha256: f30ec189e37c27e0e6320fb412dffebeeb329b81fd70412ccb2e7a4c3f26476d

Contents?: true

Size: 890 Bytes

Versions: 45

Compression:

Stored size: 890 Bytes

Contents

RSpec::Matchers.define :be_a_hash_including do |expected|
  match do |actual|
    next false unless actual.is_a? Hash
    next false unless expected.is_a? Hash
    expected.keys.each do |key|
      break false if actual[key] != expected[key]
      true
    end
  end
end

describe :be_a_hash_including do

  context 'when actual is not a Hash' do
    subject { 'I AM NOT A HASH' }
    it { should_not be_a_hash_including({}) }
  end

  context 'when expected is not a Hash' do
    subject { {} }
    it { should_not be_a_hash_including('') }
  end

  context 'when expected is included in actual' do
    subject {{:actual_key1 => 'value1'}}
    it { should be_a_hash_including({:actual_key1 => 'value1'})}
  end

  context 'when expected is not included in actual' do
    subject {{:actual_key1 => 'value1'}}
    it { should_not be_a_hash_including({:actual_key3 => 'value3'})}
  end

end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
elasticity-2.3 spec/support/be_a_hash_including_matcher.rb
elasticity-2.2 spec/support/be_a_hash_including_matcher.rb
elasticity-2.1.1 spec/support/be_a_hash_including_matcher.rb
elasticity-2.1 spec/support/be_a_hash_including_matcher.rb
elasticity-2.0 spec/support/be_a_hash_including_matcher.rb