Skip to content

Fix module's .included not run sometimes #387

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

Conversation

PikachuEXE
Copy link
Contributor

@PikachuEXE PikachuEXE commented May 13, 2025

Fixes #386

Let me know if test case can be arranged better (I spent most time figuring out what's the cause and how to reproduce in test case form

Before merging:

  • Copy the table printed at the end of the latest benchmark results into the README.md and update this PR
  • If this change merits an update to CHANGELOG.md, add an entry following Keep a Changelog guidelines with semantic versioning

Copy link

codecov bot commented May 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (16c7c4b) to head (ddf5ca7).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #387   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          196       197    +1     
  Branches        89        89           
=========================================
+ Hits           196       197    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@JacobEvelyn JacobEvelyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good other than the small test change I noted.

Would you mind also:

  • Squashing this into a single commit (with Fixes #386 in the commit description)
  • Adding this to the changelog (something along the lines of:
- Prevented overwriting of `included` in modules prepending `MemoWise` [[#387]](https://github.com/panorama-ed/memo_wise/pull/387))
  • Updating the benchmarks table in the README.md to this from the CI run:
|Method arguments|`alt_memery` (2.1.0)|`dry-core`\* (1.1.0)|`memery` (1.7.0)|`memoist3` (1.0.0)|`short_circu_it` (0.29.3)|
|--|--|--|--|--|--|
|`()` (none)|12.20x|0.57x|3.31x|2.76x|18.45x|
|`(a)`|9.75x|0.98x|3.76x|14.54x|13.96x|
|`(a, b)`|7.59x|0.82x|2.92x|11.39x|10.87x|
|`(a:)`|14.89x|0.97x|6.39x|19.76x|12.60x|
|`(a:, b:)`|12.64x|0.86x|5.43x|21.05x|10.70x|
|`(a, b:)`|12.25x|0.84x|5.22x|16.12x|10.31x|
|`(a, *args)`|1.89x|0.65x|0.73x|2.84x|2.70x|
|`(a:, **kwargs)`|2.86x|0.71x|1.21x|4.79x|2.42x|
|`(a, *args, b:, **kwargs)`|1.81x|0.62x|0.83x|3.03x|1.52x|

@@ -483,6 +483,58 @@ def child_class_method
expect(instance.child_class_method_counter).to eq(1)
end
end

context "when the class included a module which includes another module with `.included`" do
Copy link
Member

@JacobEvelyn JacobEvelyn May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this slight simplification?

context "when a module prepends MemoWise and defines `.included`" do
  let(:module_to_include) do
    Module.new do
      prepend MemoWise

      def self.included(base)
        base.class_eval do
          @internal_state = true
        end
      end

      def method1
        self.class.internal_state
      end
      memo_wise :method1
    end
  end

  let(:klass) do
    Class.new do
      include ModuleToInclude

      def self.internal_state
        @internal_state ||= false
      end
    end
  end

  let(:instance) { klass.new }

  before(:each) { stub_const("ModuleToInclude", module_to_include) }

  it "calls module `.included` method" do
    expect(instance.send(:method1)).to be true
  end
end

Or is there an even simpler version?

@PikachuEXE PikachuEXE force-pushed the fix/included-module-included-not-run branch from 92eace0 to ddf5ca7 Compare May 14, 2025 00:51
@PikachuEXE
Copy link
Contributor Author

All done

Copy link
Member

@JacobEvelyn JacobEvelyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for getting this out so quickly and making those changes. ❤️

@JacobEvelyn JacobEvelyn merged commit ca71efc into panorama-ed:main May 14, 2025
9 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.

1.12.0 causes undefined method error
2 participants