Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Issue with Differ due to new ObjectFormatter class #223

Open
hackling opened this issue Jul 10, 2015 · 2 comments
Open

Bug: Issue with Differ due to new ObjectFormatter class #223

hackling opened this issue Jul 10, 2015 · 2 comments

Comments

@hackling
Copy link
Contributor

If you use an Rspec matcher inside a hash, and there is something wrong with the hash, even if the matcher was correct, the ObjectInspector inspects the matcher before passing it to the differ, and then as a result, tells you that they didn't match.

require 'spec_helper'

describe 'issue with the new ObjectInspector' do
  let(:expectation) do
    {
      decimal: 0.000005,
      string: 'word',
    }
  end

  it 'outputs correctly' do
    expect(expectation).to match(
      decimal: be_within(0.1).of(0.000004),
      string: 'word',
    )
  end

  it 'outputs weirdly' do
    expect(expectation).to match(
      decimal: be_within(0.1).of(0.000004),
      string: 'wordx',
    )
  end
end
# Run options: exclude {:skip=>true}
#
#   1) issue with the new ObjectInspector outputs weirdly
#      Failure/Error: expect(expectation).to match(
#        expected {:decimal=>5.0e-06, :string=>"word"} to match {:decimal=>(be within 0.1 of 4.0e-06), :string=>"wordx"}
#        Diff:
#        @@ -1,3 +1,3 @@
#        -:decimal => (be within 0.1 of 4.0e-06),
#        -:string => "wordx",
#        +:decimal => 5.0e-06,
#        +:string => "word",
#
#      # ./example-breaking.rb:19:in `block (2 levels) in <top (required)>'
#
#  2/2 |============================================================ 100 ============================================================>| Time: 00:00:00
#
# Finished in 0.60996 seconds (files took 6.8 seconds to load)
#2 examples, 1 failure
#
# Failed examples:
#
# rspec ./example-breaking.rb:18 # issue with the new ObjectInspector outputs weirdly
@hackling hackling changed the title Bug: Issue with Differ due to new ObjectInspector class Bug: Issue with Differ due to new ObjectFormatter class Jul 10, 2015
@myronmarston
Copy link
Member

Yep, this is a known issue. There's some prior discussion about it in rspec/rspec-expectations#495. Given that we're doing a simple textual diff, I'm not sure what the solution is. Any ideas?

@hackling
Copy link
Contributor Author

It would have to involve something like evaluating the composed matcher, and then if it evaluates to true, maybe override the content of the hashes so that it doesn't trigger the differ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants