From 26e1f6c35e3b502981772a6e1e5ce3c372605202 Mon Sep 17 00:00:00 2001 From: Joe Stein Date: Fri, 3 Nov 2023 17:43:10 -0700 Subject: [PATCH] Add failing test for OrderedOptions --- .../support/shared_examples/active_support.rb | 42 +++++++++++++ .../active_support/object_inspection_spec.rb | 62 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 spec/unit/active_support/object_inspection_spec.rb diff --git a/spec/support/shared_examples/active_support.rb b/spec/support/shared_examples/active_support.rb index 838d04d6..66ca455a 100644 --- a/spec/support/shared_examples/active_support.rb +++ b/spec/support/shared_examples/active_support.rb @@ -64,4 +64,46 @@ end end end + + context "when comparing OrderedOptions and Hash instances", + active_record: true do + it "produces the correct failure message when used in the positive" do + as_both_colored_and_uncolored do |color_enabled| + snippet = <<~RUBY + expected = {beep: :bip} + actual = ::ActiveSupport::OrderedOptions[beep: :boop] + expect(expected).to eq(actual) + RUBY + program = + make_rspec_rails_test_program(snippet, color_enabled: color_enabled) + + expected_output = + build_expected_output( + color_enabled: color_enabled, + snippet: "expect(expected).to eq(actual)", + expectation: + proc do + line do + plain "Expected " + actual "{ beep: :bip }" + plain " to eq " + expected "#" + plain "." + end + end, + diff: + proc do + plain_line " {" + expected_line "- beep: :boop" + actual_line "+ beep: :bip" + plain_line " }" + end + ) + + expect(program).to produce_output_when_run(expected_output).in_color( + color_enabled + ) + end + end + end end diff --git a/spec/unit/active_support/object_inspection_spec.rb b/spec/unit/active_support/object_inspection_spec.rb new file mode 100644 index 00000000..448c7426 --- /dev/null +++ b/spec/unit/active_support/object_inspection_spec.rb @@ -0,0 +1,62 @@ +require "spec_helper" + +RSpec.describe SuperDiff, type: :unit do + describe ".inspect_object", + "for ActiveSupport objects", + active_support: true do + context "given an ActiveSupport::OrderedOptions object" do + context "given as_lines: false" do + it "returns an inspected version of the object" do + string = + described_class.inspect_object( + ::ActiveSupport::OrderedOptions[name: "Bob", age: 42], + as_lines: false + ) + expect(string).to eq(%(#)) + end + end + + context "given as_lines: true" do + it "returns an inspected version of the object as multiple Lines" do + tiered_lines = + described_class.inspect_object( + ::ActiveSupport::OrderedOptions[name: "Bob", age: 42], + as_lines: true, + type: :delete, + indentation_level: 1 + ) + expect(tiered_lines).to match( + [ + an_object_having_attributes( + type: :delete, + indentation_level: 1, + value: "#", + collection_bookend: :close + ) + ] + ) + end + end + end + end +end