Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Confusing RSpec hash match diff

I'm using RSpec match matcher to check if a hash contains expected values. When a key of the hash doesn't match, all the dynamic (a_string_starting_with, etc) values are shown as not matching. It's especially distracting when you try to match a bigger hash. I'm wondering if there's another way check the hash, so only the values which really do not match would show up in the diff.

Here's an example, where a is marked in red, although the value is correct.

it 'matches' do
  actual = {
    a: 'test test',
    b: 1,
    c: 2,
  }

  expect(actual).to match(
    a: a_string_starting_with('test'),
    b: 0,
    c: 2,
  )
end

Match diff

I'm wondering if there's another matcher I should use. Or if there are any custom matchers or gems for this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem with this is the current differ gem used by RSpec and they are already aware of the issue, though currently no fix exists, as can be seen by these tickets:

  • https://github.com/rspec/rspec-support/issues/365
  • https://github.com/rspec/rspec-expectations/issues/1120

One of the solutions in proposed for now in the ticket is similar to what Mosaaleb is suggesting.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!