From 71511e676862a9e28725cab01ecf3af6d691483e Mon Sep 17 00:00:00 2001 From: Kai-Uwe Humpert Date: Mon, 23 Sep 2024 12:19:01 +0200 Subject: [PATCH 1/2] Improve inspection of Module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Declares a `Module` a `Primitive`. This improves a module's description to the already nice looking one of a `Class` (see below). This also affects (considered reasonably): - `SuperDiff::EqualityMatchers::Primitive.applies_to?` - `SuperDiff::Core::RecursionGuard.guarding_recursion_of` A regression of the change would be reported by new examples (which are a copy of the examples for the class `SuperDiff::Test::Person`) like this: ``` 1) SuperDiff.inspect_object for Ruby objects given a module given as_lines: false returns the module's name Failure/Error: expect(string).to eq("SuperDiff::Test") Expected "#" to eq "SuperDiff::Test". # ./lib/super_diff/rspec/monkey_patches.rb:43:in `handle_failure' # ./spec/unit/super_diff_spec.rb:1135:in `block (5 levels) in ' 2) SuperDiff.inspect_object for Ruby objects given a module given as_lines: true returns the module's name as value Failure/Error: expect(tiered_lines).to match( [ an_object_having_attributes( type: :delete, indentation_level: 1, value: "SuperDiff::Test" ) ] ) Expected [#] to match [#] Diff: ┌ (Key) ──────────────────────────┐ │ ‹-› in expected, not in actual │ │ ‹+› in actual, not in expected │ │ ‹ › in both expected and actual │ └─────────────────────────────────┘ [ # ] # ./lib/super_diff/rspec/monkey_patches.rb:43:in `handle_failure' # ./spec/unit/super_diff_spec.rb:1148:in `block (5 levels) in ' ``` --- lib/super_diff.rb | 2 +- spec/unit/super_diff_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/super_diff.rb b/lib/super_diff.rb index bfada9e7..e177f38f 100644 --- a/lib/super_diff.rb +++ b/lib/super_diff.rb @@ -113,7 +113,7 @@ def self.date_like?(value) def self.primitive?(value) case value - when true, false, nil, Symbol, Numeric, Regexp, Class, String + when true, false, nil, Symbol, Numeric, Regexp, Class, Module, String true else false diff --git a/spec/unit/super_diff_spec.rb b/spec/unit/super_diff_spec.rb index d0cbfb17..6274c6ca 100644 --- a/spec/unit/super_diff_spec.rb +++ b/spec/unit/super_diff_spec.rb @@ -1124,6 +1124,40 @@ end end + context "given a module" do + context "given as_lines: false" do + it "returns the module's name" do + string = + described_class.inspect_object( + SuperDiff::Test, + as_lines: false + ) + expect(string).to eq("SuperDiff::Test") + end + end + + context "given as_lines: true" do + it "returns the module's name as value" do + tiered_lines = + described_class.inspect_object( + SuperDiff::Test, + as_lines: true, + type: :delete, + indentation_level: 1 + ) + expect(tiered_lines).to match( + [ + an_object_having_attributes( + type: :delete, + indentation_level: 1, + value: "SuperDiff::Test" + ) + ] + ) + end + end + end + # TODO: Add when empty context "given a custom object" do context "containing only primitive values" do From d4fe466b1262124e75aac19e4b87259f1ec4b0d5 Mon Sep 17 00:00:00 2001 From: Kai-Uwe Humpert Date: Mon, 23 Sep 2024 21:40:54 +0200 Subject: [PATCH 2/2] Fix linter warnings Whoa, a github action without any helpful output is weird. And to not have the same tool chain installed locally too. For the records: ``` # node was already installed npm install yarn yarn add lint node_modules/.bin/yarn lint:fix ``` --- spec/unit/super_diff_spec.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/unit/super_diff_spec.rb b/spec/unit/super_diff_spec.rb index 6274c6ca..35082f52 100644 --- a/spec/unit/super_diff_spec.rb +++ b/spec/unit/super_diff_spec.rb @@ -1128,10 +1128,7 @@ context "given as_lines: false" do it "returns the module's name" do string = - described_class.inspect_object( - SuperDiff::Test, - as_lines: false - ) + described_class.inspect_object(SuperDiff::Test, as_lines: false) expect(string).to eq("SuperDiff::Test") end end