I don't understand why do you need so, but you can use Hash#delete_if
RSpec.describe do
let(:hash1) { {'name' => 'XXXXX', 'age' => 29, 'DOB' => 'dd/mm/yyyy'} }
let(:hash2) { {'name' => 'XXXXX', 'age' => 29, 'DOB' => 'dd/mm/yyyy'} }
it 'should correctly compare two subhashes' do
expect(hash1.delete_if { |k,_| k == 'DOB' }).to eql(hash2.delete_if { |k,_| k == 'DOB' })
end
end
If you want to make your expect
more neatly you can convert hashes before.
Also you can use Hash#reject
RSpec.describe do
it 'should correctly compare two subhashes' do
hash1 = {'name' => 'XXXXX', 'age' => 29, 'DOB' => 'dd/mm/yyyy'}
hash2 = {'name' => 'XXXXX', 'age' => 29, 'DOB' => 'dd/mm/yyyy'}
hash1, hash2 = [hash1, hash2].map { |h| h.reject { |k,_| k == 'DOB' } }
expect(hash1).to eql(hash2)
end
end