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

Change matcher does not provide a diff #998

Open
segiddins opened this issue Jul 2, 2017 · 1 comment
Open

Change matcher does not provide a diff #998

segiddins opened this issue Jul 2, 2017 · 1 comment

Comments

@segiddins
Copy link

In the following scenario, the change matcher becomes slightly more unwieldy than existing = ...; ...; expect(...).to eq(existing) because it does not include a diff, whereas the eq matcher does:

#!/usr/bin/env ruby

require "rubygems"
require "rspec/autorun"

RSpec.describe "foo" do
  let(:super_duper_long_string) { <<-EOS }
Gummi bears bear claw lollipop carrot cake fruitcake I love. Marzipan sesame snaps caramels chocolate bar. Sesame snaps cookie cotton candy tootsie roll. Jujubes wafer jujubes sesame snaps. I love chocolate cake marzipan wafer ice cream fruitcake. Lollipop carrot cake I love donut cake I love. Dragée I love toffee. Brownie topping pastry powder I love soufflé liquorice oat cake. Dessert apple pie oat cake tiramisu croissant chocolate cake. Pie gummies soufflé soufflé cotton candy I love. Caramels ice cream jujubes. Tootsie roll danish tart bear claw.
EOS

  it "changes" do
    expect do
      super_duper_long_string.replace super_duper_long_string.split(". ").shuffle.join(". ")
    end.not_to change { super_duper_long_string }
  end
end

=>

F

Failures:

  1) foo changes
     Failure/Error:
       expect do
         super_duper_long_string.replace super_duper_long_string.split(". ").shuffle.join(". ")
       end.not_to change { super_duper_long_string }
     
       expected `super_duper_long_string` not to have changed, but did change from "Gummi bears bear claw lollipop carrot cake fruitcake I love. Marzipan sesame snaps caramels chocolat...fflé soufflé cotton candy I love. Caramels ice cream jujubes. Tootsie roll danish tart bear claw.\n" to "Lollipop carrot cake I love donut cake I love. Brownie topping pastry powder I love soufflé liquoric...s bear claw lollipop carrot cake fruitcake I love. Caramels ice cream jujubes. Dragée I love toffee"
     # Untitled.rb:12:in `block (2 levels) in <main>'

Finished in 0.05296 seconds (files took 0.10046 seconds to load)
1 example, 1 failure

Failed examples:

rspec Untitled.rb:11 # foo changes
@myronmarston
Copy link
Member

The change has not defined diffable? to return true in any circumstances, so a diff will never be generated. We could make it diffable, but we'd have to be careful to make sure it doesn't produce confusing diffs since change doesn't have normal expected/actual values.

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