Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Improve inspection of Module. [#263](https://github.com/splitwise/super_diff/pull/263) by [@phorsuedzie](https://github.com/phorsuedzie)
- Fix multiline string diff with blank lines. [#266](https://github.com/splitwise/super_diff/pull/263)
- Improve inspection of Range objects. [#267](https://github.com/splitwise/super_diff/pull/267)

## 0.13.0 - 2024-09-22

Expand Down
1 change: 1 addition & 0 deletions lib/super_diff/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Basic
InspectionTreeBuilders::TimeLike,
InspectionTreeBuilders::DateLike,
InspectionTreeBuilders::DataObject,
InspectionTreeBuilders::RangeObject,
InspectionTreeBuilders::DefaultObject
)

Expand Down
6 changes: 5 additions & 1 deletion lib/super_diff/basic/inspection_tree_builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ module InspectionTreeBuilders
:DataObject,
"super_diff/basic/inspection_tree_builders/data_object"
)
autoload :DateLike, "super_diff/basic/inspection_tree_builders/date_like"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

autoload(
:DefaultObject,
"super_diff/basic/inspection_tree_builders/default_object"
)
autoload :Hash, "super_diff/basic/inspection_tree_builders/hash"
autoload :Primitive, "super_diff/basic/inspection_tree_builders/primitive"
autoload(
:RangeObject,
"super_diff/basic/inspection_tree_builders/range_object"
)
autoload :String, "super_diff/basic/inspection_tree_builders/string"
autoload :TimeLike, "super_diff/basic/inspection_tree_builders/time_like"
autoload :DateLike, "super_diff/basic/inspection_tree_builders/date_like"
end
end
end
17 changes: 17 additions & 0 deletions lib/super_diff/basic/inspection_tree_builders/range_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SuperDiff
module Basic
module InspectionTreeBuilders
class RangeObject < Core::AbstractInspectionTreeBuilder
def self.applies_to?(value)
value.is_a?(Range)
end

def call
Core::InspectionTree.new do |t1|
t1.as_lines_when_rendering_to_lines { |t2| t2.add_text object.to_s }
end
end
end
end
end
end
31 changes: 31 additions & 0 deletions spec/integration/rspec/eq_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,37 @@
end
end

context "when comparing ranges" do
it "produces the correct failure message when used in the positive" do
as_both_colored_and_uncolored do |color_enabled|
snippet = "expect(1..5).to eq(5..6)"
program = make_plain_test_program(snippet, color_enabled: color_enabled)

expected_output =
build_expected_output(
color_enabled: color_enabled,
snippet: snippet,
newline_before_expectation: true,
expectation:
proc do
line do
plain "Expected "
actual "1..5"
plain " to eq "
expected "5..6"
plain "."
end
end,
diff: nil
)

expect(program).to produce_output_when_run(expected_output).in_color(
color_enabled
)
end
end
end

it_behaves_like "a matcher that supports elided diffs" do
let(:matcher) { :eq }
end
Expand Down
19 changes: 19 additions & 0 deletions spec/unit/basic/inspection_tree_builders/range_object_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "spec_helper"

RSpec.describe SuperDiff, type: :unit do
describe ".inspect_object" do
context "given as_lines: false" do
subject(:output) do
described_class.inspect_object(object, as_lines: false)
end

context "given a simple range" do
let(:object) { 1..5 }

it "shows the data" do
expect(output).to eq("1..5")
end
end
end
end
end