Skip to content

Conversation

ahx
Copy link
Owner

@ahx ahx commented Jun 14, 2025

OpenapiFirst::Test is now stricter and more configurable

Changes:

  • Changed OpenapiFirst::Test to raises an "invalid response" error if it sees an invalid response (OpenapiFirst::Test should complain about invalid responses even when they are skipped via skip_response_coverage #366).
    You can change this back to the old behavior by setting OpenapiFirst::Test::Configuration#response_raise_error = false (but you shouldn't).
  • Added Test.setup { it.observe(MyApp) }, Test.observe(App, api: :my_api) and internal Test::Callable[] to inject request/response validation in rack app as an alternative to overwrite the app method in a test
  • Added Test::Configuration#ignored_unknown_status to configure response status(es) that do not have to be descriped in the API description. 404 statuses are ignored by default.
  • Changed OpenapiFirst::Test to make tests fail if API description is not covered by tests. You can adapt this behavior via OpenapiFirst::Test.setup / skip_response_coverage or deactivate coverage with OpenapiFirst::Test::Configuration#report_coverage = false or report_coverage = :warn

Solves #366

@ahx ahx force-pushed the plausible-test branch from 7d2d9f2 to ddf2c90 Compare June 18, 2025 10:45
ahx added 13 commits June 18, 2025 18:18
Just like Array#delete_if or such
- OpenapiFirst::Test now raises an "invalid response" error if it sees an invalid response.
  You can change this back to the old behavior by setting `response_raise_error = false`:
  ```ruby
  OpenapiFirst::Test.setup do |test|
    # test.register(...)
    test.response_raise_error = false
  end
  ```
to configure the behavior if not all requests/responses of the API under test have been tested.

Deprecate  `OpenapiFirst::Test::Configuration#minimum_coverage=` use "#report_coverage" instead to modify the behavior
It think it's louder and clearer that way

Also avoid checking coverage and failing after our own test case is finished
by disabling exit handler via Test.uninstall

And move setup/handling at_exit from Configuration to Test
Add `OpenapiFirst::Test::Configuration#ignored_unknown_status` to configure response status(es) that do not have to be descriped in the API description.
Added `Test.setup { it.observe }` and low-level `Test::Callable[]` to inject request/response validation in rack app as an alternative to overwrite the `app` method in a test
@ahx ahx force-pushed the plausible-test branch from ddf2c90 to 7daefb3 Compare June 18, 2025 21:54
@ahx ahx force-pushed the plausible-test branch from d35b808 to 763f211 Compare June 19, 2025 20:34
ahx added 3 commits June 19, 2025 23:10
@ahx ahx marked this pull request as ready for review June 19, 2025 21:47
@ahx ahx merged commit 65c86cc into main Jun 19, 2025
32 checks passed
@ahx ahx deleted the plausible-test branch June 19, 2025 21:48
@ahx
Copy link
Owner Author

ahx commented Jun 19, 2025

…I should have squashe-merged this. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant