ncbo / ontologies_api_ruby_client

A Ruby client for accessing NCBO's hypermedia api
Other
2 stars 6 forks source link

Validate API key before running unit tests #16

Closed alexskr closed 9 months ago

alexskr commented 1 year ago

Unit tests fail with a confusing and unhelpful error when it is run with an invalid API key. A new unit test should be added to verify that the provided API key validates before proceeding to other unit tests.

relates to #14

jvendetti commented 9 months ago

The only way I could think of to verify the API key was to issue a simple API request in the base TestCase and check the response, prior to running any of the tests. This led to the interesting discovery that Minitest doesn't have built-in support for something like before(:all), which is discussed in a lot of detail in this issue. I decided to include the minitest-hooks gem, which adds this functionality.

Now if an invalid API key is provided, this is detected and the test suite is aborted, i.e.:

$ ontologies_api_ruby_client git:(master) bundle exec rake test TESTOPTS="-v"
Run options: -v --seed 53341

# Running:

ABORTED! You must provide a valid API key.
rake aborted!
Command failed with status (1)

Fixed by these commits: 4dd08e06752da2933196de22495ac99ea7eb19ed, 53f330a76dfacd99c88d5be3a122f5f3394b872d