|
756 | 756 | end |
757 | 757 | end |
758 | 758 | end |
| 759 | + |
| 760 | + context "when comparing two data structures where one contains an empty array" do |
| 761 | + it "formats the array correctly in the diff" do |
| 762 | + as_both_colored_and_uncolored do |color_enabled| |
| 763 | + snippet = <<~TEST.strip |
| 764 | + expected = { foo: nil } |
| 765 | + actual = { foo: [] } |
| 766 | + expect(actual).to eq(expected) |
| 767 | + TEST |
| 768 | + program = make_plain_test_program(snippet, color_enabled: color_enabled) |
| 769 | + |
| 770 | + expected_output = build_expected_output( |
| 771 | + color_enabled: color_enabled, |
| 772 | + snippet: %|expect(actual).to eq(expected)|, |
| 773 | + newline_before_expectation: true, |
| 774 | + expectation: proc { |
| 775 | + line do |
| 776 | + plain "Expected " |
| 777 | + green %|{ foo: [] }| |
| 778 | + plain " to eq " |
| 779 | + red %|{ foo: nil }| |
| 780 | + plain "." |
| 781 | + end |
| 782 | + }, |
| 783 | + diff: proc { |
| 784 | + plain_line %| {| |
| 785 | + red_line %|- foo: nil| |
| 786 | + green_line %|+ foo: []| |
| 787 | + plain_line %| }| |
| 788 | + } |
| 789 | + ) |
| 790 | + |
| 791 | + expect(program). |
| 792 | + to produce_output_when_run(expected_output). |
| 793 | + in_color(color_enabled) |
| 794 | + end |
| 795 | + end |
| 796 | + end |
| 797 | + |
| 798 | + context "when comparing two data structures where one contains an empty hash" do |
| 799 | + it "formats the hash correctly in the diff" do |
| 800 | + as_both_colored_and_uncolored do |color_enabled| |
| 801 | + snippet = <<~TEST.strip |
| 802 | + expected = { foo: nil } |
| 803 | + actual = { foo: {} } |
| 804 | + expect(actual).to eq(expected) |
| 805 | + TEST |
| 806 | + program = make_plain_test_program(snippet, color_enabled: color_enabled) |
| 807 | + |
| 808 | + expected_output = build_expected_output( |
| 809 | + color_enabled: color_enabled, |
| 810 | + snippet: %|expect(actual).to eq(expected)|, |
| 811 | + newline_before_expectation: true, |
| 812 | + expectation: proc { |
| 813 | + line do |
| 814 | + plain "Expected " |
| 815 | + green %|{ foo: {} }| |
| 816 | + plain " to eq " |
| 817 | + red %|{ foo: nil }| |
| 818 | + plain "." |
| 819 | + end |
| 820 | + }, |
| 821 | + diff: proc { |
| 822 | + plain_line %| {| |
| 823 | + red_line %|- foo: nil| |
| 824 | + green_line %|+ foo: {}| |
| 825 | + plain_line %| }| |
| 826 | + } |
| 827 | + ) |
| 828 | + |
| 829 | + expect(program). |
| 830 | + to produce_output_when_run(expected_output). |
| 831 | + in_color(color_enabled) |
| 832 | + end |
| 833 | + end |
| 834 | + end |
| 835 | + |
| 836 | + context "when comparing two data structures where one contains an empty object" do |
| 837 | + it "formats the object correctly in the diff" do |
| 838 | + as_both_colored_and_uncolored do |color_enabled| |
| 839 | + snippet = <<~TEST.strip |
| 840 | + expected = { foo: nil } |
| 841 | + actual = { foo: SuperDiff::Test::EmptyClass.new } |
| 842 | + expect(actual).to eq(expected) |
| 843 | + TEST |
| 844 | + program = make_plain_test_program(snippet, color_enabled: color_enabled) |
| 845 | + |
| 846 | + expected_output = build_expected_output( |
| 847 | + color_enabled: color_enabled, |
| 848 | + snippet: %|expect(actual).to eq(expected)|, |
| 849 | + newline_before_expectation: true, |
| 850 | + expectation: proc { |
| 851 | + line do |
| 852 | + plain "Expected " |
| 853 | + green %|{ foo: #<SuperDiff::Test::EmptyClass> }| |
| 854 | + plain " to eq " |
| 855 | + red %|{ foo: nil }| |
| 856 | + plain "." |
| 857 | + end |
| 858 | + }, |
| 859 | + diff: proc { |
| 860 | + plain_line %| {| |
| 861 | + red_line %|- foo: nil| |
| 862 | + green_line %|+ foo: #<SuperDiff::Test::EmptyClass>| |
| 863 | + plain_line %| }| |
| 864 | + } |
| 865 | + ) |
| 866 | + |
| 867 | + expect(program). |
| 868 | + to produce_output_when_run(expected_output). |
| 869 | + in_color(color_enabled). |
| 870 | + removing_object_ids |
| 871 | + end |
| 872 | + end |
| 873 | + end |
759 | 874 | end |
0 commit comments