-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow chained comparisons #21
base: master
Are you sure you want to change the base?
Allow chained comparisons #21
Conversation
if @comparison_type == :faster | ||
1 < @ratio && @ratio < @count | ||
1 < @ratio && @ratio < count |
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.
Style/YodaCondition: Reverse the order of the operands 1 < @ratio.
end | ||
|
||
def expected_count_matchers | ||
@expected_count_matchers.empty? ? DEFAULT_EXPECTED_COUNT_MATCHERS : @expected_count_matchers |
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.
Metrics/LineLength: Line is too long. [102/80]
expected_count_matchers | ||
.select { |_, count| count != 1 } | ||
.map { |type, count| "by #{type} #{count} times" } | ||
.join(' and ') |
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.
Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
def comparison_description | ||
expected_count_matchers | ||
.select { |_, count| count != 1 } | ||
.map { |type, count| "by #{type} #{count} times" } |
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.
Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
@@ -162,6 +156,13 @@ def failure_reason | |||
|
|||
private | |||
|
|||
def comparison_description | |||
expected_count_matchers | |||
.select { |_, count| count != 1 } |
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.
Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
|
||
it "fails if the block performance ratio is lower then indicated by at_most" do | ||
expect { | ||
expect { |
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.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
end | ||
|
||
it "fails if the block performance ratio is lower then indicated by at_most" do | ||
expect { |
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.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
}.to raise_error(/expected given block to perform faster than comparison block by at_least \d+ times and by at_most \d+ times, but performed faster by \d+.\d+ times/) | ||
end | ||
|
||
it "fails if the block performance ratio is lower then indicated by at_most" 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.
Metrics/LineLength: Line is too long. [85/80]
expect { 1 << 1 } | ||
.to perform_faster_than { 'x' * 10 * 1024 } | ||
.at_least(2).at_most(15).times | ||
}.to raise_error(/expected given block to perform faster than comparison block by at_least \d+ times and by at_most \d+ times, but performed faster by \d+.\d+ times/) |
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.
Metrics/LineLength: Line is too long. [174/80]
expect { | ||
expect { 1 << 1 } | ||
.to perform_faster_than { 'x' * 10 * 1024 } | ||
.at_least(2).at_most(15).times |
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.
Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
@piotrmurach , not sure what's the proper way to deal with rubocop issues. Seems like the other code in the file is written ignoring them so I tried to keep the code consistent |
@piotrmurach, what should I do in order to merge this PR? |
This is awesome! Ping @piotrmurach |
@piotrmurach Please consider this! |
Hi @povilasjurcys, Thank your contribution to The drawbacks section is important to me. It tells me how thoroughly a feature has been considered before I review anything. There are always drawbacks, even considering increased complexity and maintenance. Further, to add to the considerations:
Most importantly, is it true that we reduce the risk of false positives by allowing chaining? I mean, when we use, for example, the @pboling I appreciate your enthusiasm for this feature. Emojis are fine, I appreciate the feedback. However, please bear in mind that my time is limited and my priorities in open source do not necessarily align with what others want at a given moment. I have a lot of gems to maintain - nearly 70. If you wonder how you can help push things forward. You can do so by reviewing the patch code and providing a critical evaluation of the approach. |
Describe the change
This PR allows setting
at_most(x).at_least(x)
without overriding previously defined expectations.before the change:
after the change
Why are we doing this?
When testing performance with a comparison matcher it's almost impossible to set an
exact
value - each machine will perform a bit differently. But we can set a range where we expect the comparison to fall. Sadly it's hard to do so in an intuitive way as it's not possible to set minimum and maximum count for a single case. Having the possibility to set min and max times count would prevent from false-positives and allow us to better notice changes in performance,Benefits
Drawbacks
Possible drawbacks applying this change: 🤷
Requirements
master
branch?