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

Ruby: Example of how awesome inline expectations test are #13

Open
wants to merge 3 commits into
base: ruby-update-ssrf-concept
Choose a base branch
from

Conversation

RasmusWL
Copy link
Owner

@RasmusWL RasmusWL commented Mar 22, 2022

This PR is an example of how inline expectation tests can make your life sweet and nice.

Notice that's it's based on the change in github#8524 (partly because I was lazy and already had that branch checked out, partly because it allowed me to copy the inline expectation test verbatim from Python 😉)

I have only changed one framework in (Excon.rb), and only the part about what URL is requested and whether certificate check is disabled (so not what the request body is). Hopefully that should be enough to show off what it can do 😉

Please see this commit-by-commit

I can also recommend reading the documentation of the framework in https://github.com/github/codeql/blob/main/ruby/ql/test/TestUtilities/InlineExpectationsTest.qll

But you _should_ be keeping your .expected file for such tests empty at
all times, such that changes are recorded in the annotations in the
code.
It's a nightmare to review the `HttpClients.expected` file, but
everything just works with the inline expectation tests.

Note: Since I added that fake SPURIOUS annotation to highlight what you
_can_ do with this testing framework, there is actually one change to
the .expected output, but again, you should keep that file without
results by changing the inline annotations in the test file.
@github-actions github-actions bot added the Ruby label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant