Skip to content
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

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Apr 18, 2024

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.

@mkllnk mkllnk self-assigned this Apr 18, 2024
@mkllnk mkllnk marked this pull request as ready for review April 18, 2024 22:32
Copy link

@rioug rioug 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 ! I left a note with a small improvement but It shouldn't block merging.

end

def query_summary
QuerySummary.new(@queries).summary
Copy link

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.

Copy link
Member Author

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.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work!

Comment on lines 60 to 67
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
Copy link
Member

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 😞

Copy link
Member Author

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.

@mkllnk mkllnk merged commit 31b2c55 into main Apr 23, 2024
2 checks passed
@mkllnk mkllnk deleted the error-messages branch April 23, 2024 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Tailor error message based on numeric matching format
3 participants