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

Document how to set up response validation with Minitest #794

Open
TastyPi opened this issue Oct 3, 2022 · 5 comments
Open

Document how to set up response validation with Minitest #794

TastyPi opened this issue Oct 3, 2022 · 5 comments
Labels

Comments

@TastyPi
Copy link

TastyPi commented Oct 3, 2022

There's lots of great examples on how to use this library with RSpec, but I can't find anything for Minitest. Is there a way to set up Minitest to validate Apipie responses? If so, could it be documented somewhere?

@logeyG
Copy link

logeyG commented Jan 23, 2023

Hi @TastyPi, I'm looking into this myself now as well. Did you ever find any more resources?

I am assuming using Minitest with ApiPie is possible, it's just we lack documentation.

@TastyPi
Copy link
Author

TastyPi commented Jan 23, 2023

@logeyG I assume it is possible, but I haven't had the time to look into it.

@mathieujobin
Copy link
Collaborator

Maybe you could be more specific about what exactly you want to test?
if I take this spec file for example, that tests a validator.

https://github.com/Apipie/apipie-rails/blob/master/spec/lib/validators/array_validator_spec.rb

converting it from rspec to minitest would mean replacing all the expect().to foo by some assert bar; no ?

@logeyG
Copy link

logeyG commented Jan 30, 2023

thanks @mathieujobin for the response

I'm interested in doing something like this as referenced in the docs: https://github.com/Apipie/apipie-rails#example-of-the-manual-mechanism

Our codebase is very tied to Minitest so I don't think introducing RSpec is viable for us to be able to use this.

However based on what you wrote above, I think all that would be required is to convert the following block of code in response_validation_helper.rb to something that is Minitest compatible?

RSpec::Matchers.define :match_declared_responses do
  match do |actual|
    (schema, validation_errors) = subject.send(:schema_validation_errors_for_response)
    valid = (validation_errors == [])
    Apipie::print_validation_errors(validation_errors, schema, response) unless valid

    valid
  end
end

@mathieujobin
Copy link
Collaborator

Yes that's correct.

Rspec matcher are just syntaxic sugar...

Définition can be taken pretty much as-is...

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

No branches or pull requests

3 participants