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

Commit c14d0a6

Browse files
committed
Add helper to support other libraries expecting diffs
1 parent 1e818a1 commit c14d0a6

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

lib/rspec/support/spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'rspec/support/spec/in_sub_process'
33

44
RSpec::Support.require_rspec_support "spec/deprecation_helpers"
5+
RSpec::Support.require_rspec_support "spec/diff_helpers"
56
RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
67
RSpec::Support.require_rspec_support "spec/stderr_splitter"
78
RSpec::Support.require_rspec_support "spec/formatting_support"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'diff/lcs'
2+
3+
module RSpec::Support
4+
module Spec
5+
module DiffHelpers
6+
# In the updated version of diff-lcs several diff headers change format slightly
7+
# compensate for this and change minimum version in RSpec 4
8+
if ::Diff::LCS::VERSION.to_f < 1.4
9+
def one_line_header(line_number = 2)
10+
"-1,#{line_number} +1,#{line_number}"
11+
end
12+
13+
def removing_two_line_header
14+
"-1,3 +1"
15+
end
16+
else
17+
def one_line_header(_ = 2)
18+
"-1 +1"
19+
end
20+
21+
def removing_two_line_header
22+
"-1,3 +1,5"
23+
end
24+
end
25+
end
26+
end
27+
end

spec/rspec/support/differ_spec.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@
77
module RSpec
88
module Support
99
RSpec.describe Differ do
10-
11-
# In the updated version of diff-lcs several diff headers change format slightly
12-
# compensate for this and change minimum version in RSpec 4
13-
if Diff::LCS::VERSION.to_f < 1.4
14-
one_line_header = "-1,2 +1,2"
15-
removing_two_line_header = "-1,3 +1"
16-
else
17-
one_line_header = "-1 +1"
18-
removing_two_line_header = "-1,3 +1,5"
19-
end
10+
include Spec::DiffHelpers
2011

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

0 commit comments

Comments
 (0)