Skip to content

Improve inspection of Module #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

phorsuedzie
Copy link
Contributor

@phorsuedzie phorsuedzie commented Sep 23, 2024

A module's inspection (used e.g. generate a description of an RSpec example) has been improved to now include the module's name, which identifies the module better than the previous string.

Old: #<Module:0x0000000107f7a0a0>
New (e.g.): SuperDiff::Test.

The improvement declares a Module a Primitive (which is what has been used for a Class already).

Closes #255.

FYI: Most of the time was spent to get the specs run locally. See 24b8183.

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 "#<Module:0x0000000107f7a0a0>" 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 <top (required)>'

  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 [#<SuperDiff::Core::Line:0x0000000112e58a40 @add_comma=false, @children=[], @collection_bookend=nil, @complete_bookend=nil, @elided=false, @indentation_level=1, @Prefix="", @type=:delete, @value="#<Module:0x0000000107f7a0a0>">]
       to match [#<an object having attributes (type: :delete, indentation_level: 1, value: "SuperDiff::Test")>]

       Diff:

       ┌ (Key) ──────────────────────────┐
       │ ‹-› in expected, not in actual  │
       │ ‹+› in actual, not in expected  │
       │ ‹ › in both expected and actual │
       └─────────────────────────────────┘

         [
           #<SuperDiff::Core::Line:0x0000000112e58a40 {
             @type=:delete,
             @indentation_level=1,
       -     @value="SuperDiff::Test"
       +     @value="#<Module:0x0000000107f7a0a0>"
           }>
         ]
     # ./lib/super_diff/rspec/monkey_patches.rb:43:in `handle_failure'
     # ./spec/unit/super_diff_spec.rb:1148:in `block (5 levels) in <top (required)>'
```
@phorsuedzie phorsuedzie force-pushed the improve-inspect-module branch from 2330d05 to 71511e6 Compare September 23, 2024 18:59
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
```
@jas14 jas14 self-assigned this Sep 24, 2024
@jas14 jas14 self-requested a review September 24, 2024 17:07
@jas14
Copy link
Collaborator

jas14 commented Sep 25, 2024

Thanks for the PR, @phorsuedzie ! I'll take a look soon. I want to address your setup comments – I think we could improve the linter. I'm considering switching back to Rubocop or another Ruby-based linter to keep things in the same ecosystem.

@jas14 jas14 merged commit 7d1a4ce into splitwise:main Sep 25, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a Module to be displayed similar to a Class, as a "primitive"
3 participants