-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve failure messages when not expecting a list #5
Conversation
This prepares for adding more related logic there.
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 ! I left a note with a small improvement but It shouldn't block merging.
end | ||
|
||
def query_summary | ||
QuerySummary.new(@queries).summary |
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.
To minimise the dependency on QuerySummary
, I would inject it in the constructor like this :
def initialize(queries, expected, query_summary=QuerySummary)
...
end
Now you are depending on an object that implement summary
and not QuerySummary
directly.
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.
I think it's okay to depend on QuerySummary here. It means that the calling module doesn't need to know the QuerySummary. It reduces the API and the matcher definition doesn't need to know which class is responsible for which format.
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.
Great work!
def diff(actual, expected) | ||
if expected.is_a?(Numeric) | ||
change = actual - expected | ||
format("%+d", change) | ||
else | ||
Expectations.differ.diff_as_object(actual, expected) | ||
end | ||
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.
I guess differ
doesn't provide a method for integers, that's sad 😞
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.
Yes, I searched through a lot of RSpec code and couldn't find any differ doing this.
The first version of this matcher was just comparing lists of SQL commands. Then we supported more formats like numbers and summary hashes. But the failure messages were still referring to the list of queries and it wasn't easy to see the the difference between expectation and actual outcome. Now we use the same format for failure messages that is used for comparing against expectations.