-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix module's .included
not run sometimes
#387
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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|
spec/memo_wise_spec.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
92eace0
to
ddf5ca7
Compare
All done |
There was a problem hiding this 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. ❤️
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:
README.md
and update this PRCHANGELOG.md
, add an entry following Keep a Changelog guidelines with semantic versioning