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

Commit

Permalink
Add helper to support other libraries expecting diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Jun 28, 2020
1 parent 1e818a1 commit a18b46d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/rspec/support/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rspec/support/spec/in_sub_process'

RSpec::Support.require_rspec_support "spec/deprecation_helpers"
RSpec::Support.require_rspec_support "spec/diff_helpers"
RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
RSpec::Support.require_rspec_support "spec/stderr_splitter"
RSpec::Support.require_rspec_support "spec/formatting_support"
Expand Down
29 changes: 29 additions & 0 deletions lib/rspec/support/spec/diff_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'diff/lcs'

module RSpec
module Support
module Spec
module DiffHelpers
# In the updated version of diff-lcs several diff headers change format slightly
# compensate for this and change minimum version in RSpec 4
if ::Diff::LCS::VERSION.to_f < 1.4
def one_line_header(line_number=2)
"-1,#{line_number} +1,#{line_number}"
end

def removing_two_line_header
"-1,3 +1"
end
else
def one_line_header(_=2)
"-1 +1"
end

def removing_two_line_header
"-1,3 +1,5"
end
end
end
end
end
end
11 changes: 1 addition & 10 deletions spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@
module RSpec
module Support
RSpec.describe Differ do

# In the updated version of diff-lcs several diff headers change format slightly
# compensate for this and change minimum version in RSpec 4
if Diff::LCS::VERSION.to_f < 1.4
one_line_header = "-1,2 +1,2"
removing_two_line_header = "-1,3 +1"
else
one_line_header = "-1 +1"
removing_two_line_header = "-1,3 +1,5"
end
include Spec::DiffHelpers

describe '#diff' do
let(:differ) { RSpec::Support::Differ.new }
Expand Down

0 comments on commit a18b46d

Please sign in to comment.