Skip to content

Commit

Permalink
Merge pull request #1268 from rspec/remove-diff-helpers
Browse files Browse the repository at this point in the history
Bump diff-lcs to 1.4.4+
  • Loading branch information
JonRowe committed Dec 30, 2020
2 parents 8bef2ea + 10ee659 commit bf9db76
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- 2.3
env:
-
DIFF_LCS_VERSION: "> 1.4.3"
BOGUS: ""
include:
- ruby: ruby-head
env:
Expand Down
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
end
end

if ENV['DIFF_LCS_VERSION']
gem 'diff-lcs', ENV['DIFF_LCS_VERSION']
else
gem 'diff-lcs', '~> 1.4', '>= 1.4.3'
end

gem 'coderay' # for syntax highlighting
gem 'yard', '~> 0.9.24', :require => false

Expand Down
74 changes: 2 additions & 72 deletions features/custom_matchers/define_diffable_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Feature: define diffable matcher

When a matcher is defined as diffable, the output will include a diff of the submitted objects when the objects are more than simple primitives.

@skip-when-diff-lcs-1.3
Scenario: define a diffable matcher (with diff-lcs 1.4)
Scenario: define a diffable matcher
Given a file named "diffable_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :be_just_like do |expected|
Expand All @@ -27,34 +26,7 @@ Feature: define diffable matcher
+two
"""

@skip-when-diff-lcs-1.4
Scenario: define a diffable matcher (with diff-lcs 1.3)
Given a file named "diffable_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :be_just_like do |expected|
match do |actual|
actual == expected
end
diffable
end
RSpec.describe "two\nlines" do
it { is_expected.to be_just_like("three\nlines") }
end
"""
When I run `rspec ./diffable_matcher_spec.rb`
Then it should fail with:
"""
Diff:
@@ -1,3 +1,3 @@
-three
+two
lines
"""

@skip-when-diff-lcs-1.3 @skip-when-diff-lcs-1.4.3
Scenario: Redefine actual (with diff-lcs 1.4.4)
Scenario: Redefine actual

Sometimes is neccessary to overwrite actual to make diffing work, e.g. if `actual` is a name of a file you want to read from. For this to work you need to overwrite `@actual` in your matcher.

Expand Down Expand Up @@ -97,45 +69,3 @@ Feature: define diffable matcher
Data
-here
"""

@skip-when-diff-lcs-1.4
Scenario: Redefine actual (with diff-lcs 1.3)
Given a file named "redefine_actual_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :have_content do |expected|
match do |actual|
@actual = File.read(actual).chomp
values_match? expected, @actual
end
diffable
end
RSpec.describe 'Compare files' do
context 'when content is equal' do
it { expect('data.txt').to have_content 'Data' }
end
context 'when files are different' do
it { expect('data.txt').to have_content "No\nData\nhere" }
end
end
"""
And a file named "data.txt" with:
"""
Data
"""
When I run `rspec ./redefine_actual_matcher_spec.rb --format documentation`
Then the exit status should not be 0
And the output should contain:
"""
2 examples, 1 failure
"""
And the output should contain:
"""
@@ -1,4 +1,2 @@
-No
Data
-here
"""
30 changes: 1 addition & 29 deletions features/diffing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ Feature: diffing
string
"""

@skip-when-diff-lcs-1.3
Scenario: diff for a multiline string and a regexp on diff-lcs 1.4
Scenario: diff for a multiline string and a regexp
Given a file named "example_spec.rb" with:
"""ruby
RSpec.describe "a multiline string" do
Expand All @@ -59,33 +58,6 @@ Feature: diffing
+ string
"""

@skip-when-diff-lcs-1.4
Scenario: diff for a multiline string and a regexp on diff-lcs 1.3
Given a file named "example_spec.rb" with:
"""ruby
RSpec.describe "a multiline string" do
it "is like another string" do
expected = /expected/m
actual = <<-ACTUAL
this is the
actual
string
ACTUAL
expect(actual).to match expected
end
end
"""
When I run `rspec example_spec.rb`
Then the output should contain:
"""
Diff:
@@ -1,2 +1,4 @@
-/expected/m
+this is the
+ actual
+ string
"""

Scenario: no diff for a single line strings
Given a file named "example_spec.rb" with:
"""ruby
Expand Down
25 changes: 0 additions & 25 deletions features/support/diff_lcs_versions.rb

This file was deleted.

2 changes: 1 addition & 1 deletion rspec-expectations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "rspec-support", "~> #{RSpec::Expectations::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
end

s.add_runtime_dependency "diff-lcs", ">= 1.2.0", "< 2.0"
s.add_runtime_dependency "diff-lcs", ">= 1.4.4", "< 2.0"

s.add_development_dependency "aruba", "~> 0.14.10"
s.add_development_dependency 'cucumber', '~> 1.3'
Expand Down
8 changes: 2 additions & 6 deletions spec/rspec/expectations/fail_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
end

RSpec.describe RSpec::Expectations, "#fail_with with matchers" do
include RSpec::Support::Spec::DiffHelpers

before do
allow(RSpec::Matchers.configuration).to receive_messages(:color? => false)
end
Expand All @@ -44,7 +42,7 @@

expected_diff = dedent(<<-EOS)
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-["poo", "car"]
|+[(a string matching /foo/), (a string matching /bar/)]
|
Expand All @@ -57,16 +55,14 @@
end

RSpec.describe RSpec::Expectations, "#fail_with with --color" do
include RSpec::Support::Spec::DiffHelpers

before do
allow(RSpec::Matchers.configuration).to receive_messages(:color? => true)
end

it "tells the differ to use color" do
expected = "foo bar baz\n"
actual = "foo bang baz\n"
expected_diff = "\e[0m\n\e[0m\e[34m@@ #{one_line_header} @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
expected_diff = "\e[0m\n\e[0m\e[34m@@ -1 +1 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"

expect {
RSpec::Expectations.fail_with "message", actual, expected
Expand Down
7 changes: 2 additions & 5 deletions spec/rspec/matchers/built_in/have_attributes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
RSpec.describe "#have_attributes matcher" do
include RSpec::Support::Spec::DiffHelpers

Person = Struct.new(:name, :age)

class Person
Expand Down Expand Up @@ -71,7 +69,7 @@ def count
allow(RSpec::Matchers.configuration).to receive_messages(:color? => false)

expected_diff = dedent(<<-EOS)
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-:name => "Wrong Name",
|+:name => "Correct name",
EOS
Expand Down Expand Up @@ -166,11 +164,10 @@ def count
allow(RSpec::Matchers.configuration).to receive_messages(:color? => false)

expected_diff = dedent(<<-EOS)
|@@ #{one_line_header(3)} @@
|@@ -1 +1 @@
|-:age => 11,
|+:age => 33,
EOS
expected_diff << "\n :name => \"Correct name\",\n" if Diff::LCS::VERSION.to_f < 1.4

expect {
expect(person).to have_attributes(:name => correct_name, :age => wrong_age)
Expand Down
10 changes: 3 additions & 7 deletions spec/rspec/matchers/built_in/include_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def to_hash
end

RSpec.describe "#include matcher" do
include RSpec::Support::Spec::DiffHelpers

it "is diffable" do
expect(include("a")).to be_diffable
end
Expand Down Expand Up @@ -89,14 +87,12 @@ def hash.send; :sent; end
|+"foo" => 1,
END
else
diff = dedent(<<-END)
dedent(<<-END)
|Diff:
|@@ #{one_line_header(3)} @@
|@@ -1 +1 @@
|-:bar => 3,
|+:bar => 2,
END
diff << "\n :foo => 1,\n" if Diff::LCS::VERSION.to_f < 1.4
diff
end

expect {
Expand Down Expand Up @@ -391,7 +387,7 @@ class PseudoHash < SimpleDelegator
)
}.to fail_including(dedent(<<-END))
|Diff:
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-[{:number=>1}, {:number=>0}, {:number=>3}]
|+[{:number=>1}, {:number=>2}, {:number=>3}]
END
Expand Down
4 changes: 1 addition & 3 deletions spec/rspec/matchers/built_in/match_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
RSpec.describe "expect(...).to match(expected)" do
include RSpec::Support::Spec::DiffHelpers

it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
let(:matcher) { match(/a/) }
end
Expand Down Expand Up @@ -70,7 +68,7 @@

failure_message_that_includes_diff = %r|
\s*Diff:
\s*@@ #{Regexp.escape one_line_header} @@
\s*@@ \-1 \+1 @@
\s*-/bar/
\s*\+"foo"|

Expand Down
8 changes: 1 addition & 7 deletions spec/rspec/matchers/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,7 @@ def foo
diff = e.message.sub(/\A.*Diff:/m, "Diff:").gsub(/^\s*/, '')
end

if Diff::LCS::VERSION.to_f < 1.4
expected_diff = "Diff:\n@@ -1,3 +1,3 @@\n-line1\n+LINE1\nline2\n"
else
expected_diff = "Diff:\n@@ -1 +1 @@\n-line1\n+LINE1\n"
end

expect(diff).to eq expected_diff
expect(diff).to eq "Diff:\n@@ -1 +1 @@\n-line1\n+LINE1\n"
end

it 'does not confuse the diffability of different matchers' do
Expand Down

0 comments on commit bf9db76

Please sign in to comment.