Skip to content

Commit e552b75

Browse files
committed
Merge branch 'main' into rubocop
2 parents 17e79d6 + 9e13afc commit e552b75

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

1011
### Other changes
1112

lib/super_diff/basic.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Basic
2929
InspectionTreeBuilders::TimeLike,
3030
InspectionTreeBuilders::DateLike,
3131
InspectionTreeBuilders::DataObject,
32+
InspectionTreeBuilders::RangeObject,
3233
InspectionTreeBuilders::DefaultObject
3334
)
3435

lib/super_diff/basic/inspection_tree_builders.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ module InspectionTreeBuilders
1212
:DataObject,
1313
'super_diff/basic/inspection_tree_builders/data_object'
1414
)
15+
autoload :DateLike, 'super_diff/basic/inspection_tree_builders/date_like'
1516
autoload(
1617
:DefaultObject,
1718
'super_diff/basic/inspection_tree_builders/default_object'
1819
)
1920
autoload :Hash, 'super_diff/basic/inspection_tree_builders/hash'
2021
autoload :Primitive, 'super_diff/basic/inspection_tree_builders/primitive'
22+
autoload(
23+
:RangeObject,
24+
'super_diff/basic/inspection_tree_builders/range_object'
25+
)
2126
autoload :String, 'super_diff/basic/inspection_tree_builders/string'
2227
autoload :TimeLike, 'super_diff/basic/inspection_tree_builders/time_like'
23-
autoload :DateLike, 'super_diff/basic/inspection_tree_builders/date_like'
2428
end
2529
end
2630
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module SuperDiff
4+
module Basic
5+
module InspectionTreeBuilders
6+
class RangeObject < Core::AbstractInspectionTreeBuilder
7+
def self.applies_to?(value)
8+
value.is_a?(Range)
9+
end
10+
11+
def call
12+
Core::InspectionTree.new do |t1|
13+
t1.as_lines_when_rendering_to_lines { |t2| t2.add_text object.to_s }
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end

spec/integration/rspec/eq_matcher_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,37 @@
10581058
end
10591059
end
10601060

1061+
context 'when comparing ranges' do
1062+
it 'produces the correct failure message when used in the positive' do
1063+
as_both_colored_and_uncolored do |color_enabled|
1064+
snippet = 'expect(1..5).to eq(5..6)'
1065+
program = make_plain_test_program(snippet, color_enabled: color_enabled)
1066+
1067+
expected_output =
1068+
build_expected_output(
1069+
color_enabled: color_enabled,
1070+
snippet: snippet,
1071+
newline_before_expectation: true,
1072+
expectation:
1073+
proc do
1074+
line do
1075+
plain 'Expected '
1076+
actual '1..5'
1077+
plain ' to eq '
1078+
expected '5..6'
1079+
plain '.'
1080+
end
1081+
end,
1082+
diff: nil
1083+
)
1084+
1085+
expect(program).to produce_output_when_run(expected_output).in_color(
1086+
color_enabled
1087+
)
1088+
end
1089+
end
1090+
end
1091+
10611092
it_behaves_like 'a matcher that supports elided diffs' do
10621093
let(:matcher) { :eq }
10631094
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe SuperDiff, type: :unit do
6+
describe '.inspect_object' do
7+
context 'given as_lines: false' do
8+
subject(:output) do
9+
described_class.inspect_object(object, as_lines: false)
10+
end
11+
12+
context 'given a simple range' do
13+
let(:object) { 1..5 }
14+
15+
it 'shows the data' do
16+
expect(output).to eq('1..5')
17+
end
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)