Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Differ wrongly highlights BigDecimals in a hash where another element doesn't match. #335

Closed
@tomekn

Description

@tomekn

Hi!

I've encountered an issue with the differ that feels wrong.

Let's take this class as an example...

require 'bigdecimal'

class HashGenerator
  def self.generate
    {
      hello: 'world',
      decimal1: BigDecimal.new("10"),
      decimal2: BigDecimal.new("29.32")
    }
  end
end

Simple enough, let's test that our hash has the right values.

require 'hash_generator'
require 'bigdecimal'

RSpec.describe HashGenerator, '#self.generate' do
  it 'returns the expected hash' do
    expected_hash = {
      hello: 'world',
      decimal1: BigDecimal.new("10"),
      decimal2: BigDecimal.new("29.32")
    }
    expect(HashGenerator.generate).to eq(expected_hash)
  end
end

Green - all good!

Now let's change the expectation by altering the hello string, note that the bigdecimals are unchanged...

require 'hash_generator'
require 'bigdecimal'

RSpec.describe HashGenerator, '#self.generate' do
  it 'returns the expected hash' do
    expected_hash = {
      hello: 'SOME DIFFERENT STRING',
      decimal1: BigDecimal.new("10"),
      decimal2: BigDecimal.new("29.32")
    }
    expect(HashGenerator.generate).to eq(expected_hash)
  end
end

screen

The test fails as expected - but the diff also highlights the bigdecimals as a problem. I understand this is because the BigDecimal inspect contains the object id and the differ probably looks at the stringified version of the hash when it's doing its thing?

Anyway, a more complex permutation of this has led me down a wild goose chase yesterday and I thought I'd raise it here. I'm happy to work on a solution if there is consensus that this is undesired behaviour.

Thanks,

Tom

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions