rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Change matcher does not provide a diff

Open segiddins opened this issue 8 years ago • 1 comments

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

segiddins avatar Jul 02 '17 12:07 segiddins

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.

myronmarston avatar Jul 03 '17 06:07 myronmarston

Closing due to inactivity during the monorepo migration.

JonRowe avatar Nov 27 '24 21:11 JonRowe