File tree Expand file tree Collapse file tree 6 files changed +74
-1
lines changed
unit/basic/inspection_tree_builders Expand file tree Collapse file tree 6 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
2630end
Original file line number Diff line number Diff line change 1+ module SuperDiff
2+ module Basic
3+ module InspectionTreeBuilders
4+ class RangeObject < Core ::AbstractInspectionTreeBuilder
5+ def self . applies_to? ( value )
6+ value . is_a? ( Range )
7+ end
8+
9+ def call
10+ Core ::InspectionTree . new do |t1 |
11+ t1 . as_lines_when_rendering_to_lines { |t2 | t2 . add_text object . to_s }
12+ end
13+ end
14+ end
15+ end
16+ end
17+ end
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ require "spec_helper"
2+
3+ RSpec . describe SuperDiff , type : :unit do
4+ describe ".inspect_object" do
5+ context "given as_lines: false" do
6+ subject ( :output ) do
7+ described_class . inspect_object ( object , as_lines : false )
8+ end
9+
10+ context "given a simple range" do
11+ let ( :object ) { 1 ..5 }
12+
13+ it "shows the data" do
14+ expect ( output ) . to eq ( "1..5" )
15+ end
16+ end
17+ end
18+ end
19+ end
You can’t perform that action at this time.
0 commit comments