-
Notifications
You must be signed in to change notification settings - Fork 25
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
100% code coverage #62
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,9 +132,7 @@ def public_memowise_method | |
memo_wise :public_memowise_method | ||
public :public_memowise_method | ||
|
||
def unmemoized_method | ||
"unmemoized" | ||
end | ||
def unmemoized_method; end | ||
end | ||
end | ||
|
||
|
@@ -276,19 +274,45 @@ def unmemoized_method | |
expect(instance2.no_args_counter).to eq(0) | ||
end | ||
|
||
it "keeps private methods private" do | ||
expect(instance.private_methods.include?(:private_memowise_method)). | ||
to eq(true) | ||
context "with private methods" do | ||
it "keeps private methods private" do | ||
expect(instance.private_methods.include?(:private_memowise_method)). | ||
to eq(true) | ||
end | ||
|
||
it "memoizes private methods" do | ||
expect(Array.new(4) do | ||
instance.send(:private_memowise_method) | ||
end).to all eq("private_memowise_method") | ||
expect(instance.private_memowise_method_counter).to eq(1) | ||
end | ||
end | ||
|
||
it "keeps public methods public" do | ||
expect(instance.public_methods.include?(:public_memowise_method)). | ||
to eq(true) | ||
context "with public methods" do | ||
it "keeps public methods public" do | ||
expect(instance.public_methods.include?(:public_memowise_method)). | ||
to eq(true) | ||
end | ||
|
||
it "memoizes public methods" do | ||
expect(Array.new(4) { instance.public_memowise_method }). | ||
to all eq("public_memowise_method") | ||
expect(instance.public_memowise_method_counter).to eq(1) | ||
end | ||
end | ||
|
||
it "keeps protected methods protected" do | ||
expect(instance.protected_methods.include?(:protected_memowise_method)). | ||
to eq(true) | ||
context "with protected methods" do | ||
it "keeps protected methods protected" do | ||
expect(instance.protected_methods.include?(:protected_memowise_method)). | ||
to eq(true) | ||
end | ||
|
||
it "memoizes protected methods" do | ||
expect(Array.new(4) do | ||
instance.send(:protected_memowise_method) | ||
end).to all eq("protected_memowise_method") | ||
expect(instance.protected_memowise_method_counter).to eq(1) | ||
end | ||
end | ||
|
||
context "when the name of the method to memoize is not a symbol" do | ||
|
@@ -396,6 +420,24 @@ def no_args | |
expect(instance.with_keyword_args_counter).to eq(3) | ||
end | ||
|
||
it "resets memoization for methods with positional and keyword args" do | ||
instance.with_positional_and_keyword_args(1, b: 2) | ||
instance.with_positional_and_keyword_args(2, b: 3) | ||
instance.reset_memo_wise(:with_positional_and_keyword_args, 1, b: 2) | ||
|
||
expect(Array.new(4) do | ||
instance.with_positional_and_keyword_args(1, b: 2) | ||
end).to all eq("with_positional_and_keyword_args: a=1, b=2") | ||
|
||
expect(Array.new(4) do | ||
instance.with_positional_and_keyword_args(2, b: 3) | ||
end).to all eq("with_positional_and_keyword_args: a=2, b=3") | ||
|
||
# This should be executed twice for each set of arguments passed, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is a little confusing—it's really once for each set of arguments passed, which is twice total. Could you rephrase this? |
||
# and a third time for the set of arguments that was reset. | ||
expect(instance.with_positional_and_keyword_args_counter).to eq(3) | ||
end | ||
|
||
it "resets memoization for methods with special characters in the name" do | ||
instance.special_chars? | ||
instance.reset_memo_wise(:special_chars?) | ||
|
@@ -608,6 +650,37 @@ def no_args | |
end | ||
end | ||
|
||
context "with positional and keyword args" do | ||
let(:expected_counter) { overriding ? 2 : 0 } | ||
|
||
before(:each) do | ||
if overriding | ||
instance.with_positional_and_keyword_args(1, b: 2) | ||
instance.with_positional_and_keyword_args(2, b: 3) | ||
end | ||
end | ||
|
||
it "presets memoization" do | ||
instance.preset_memo_wise( | ||
:with_positional_and_keyword_args, 1, b: 2 | ||
) { "first" } | ||
instance.preset_memo_wise( | ||
:with_positional_and_keyword_args, 2, b: 3 | ||
) { "second" } | ||
|
||
expect(Array.new(4) do | ||
instance.with_positional_and_keyword_args(1, b: 2) | ||
end).to all eq("first") | ||
|
||
expect(Array.new(4) do | ||
instance.with_positional_and_keyword_args(2, b: 3) | ||
end).to all eq("second") | ||
|
||
expect(instance.with_positional_and_keyword_args_counter). | ||
to eq(expected_counter) | ||
end | ||
end | ||
|
||
context "with special chars" do | ||
before(:each) { instance.special_chars? if overriding } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
# SimpleCov.refuse_coverage_drop is only implemented for line coverage, so for | ||
# branch coverage we must use `minimum_coverage` | ||
SimpleCov.minimum_coverage branch: 90 | ||
SimpleCov.minimum_coverage branch: 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
|
||
SimpleCov.refuse_coverage_drop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have strong feelings, but it might be more explicit if we changed this to also be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to leave as is for now! I have a PR up on SimpleCov to hopefully get branch coverage working for |
||
end | ||
|
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.
This might be clearer as
(And same comment below.) Thoughts?