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

Reset config changes before each test #64

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

rossta
Copy link
Contributor

@rossta rossta commented Sep 28, 2023

Problem

While running tests locally with Ruby 3+, the logger sometimes outputs to $stdout which creates noisy test output.

To reproduce, run tests on Ruby 3.2 with bundle exec rspec --seed 27884:

$ be rspec --seed 27884

.............................................................................................................................................................................I, [2023-09-27T21:55:31.949858 #79021]  INFO -- request: GET http://netbox.test/api/virtualization/clusters.json?limit=42
I, [2023-09-27T21:55:31.949909 #79021]  INFO -- request: Authorization: "Token this-is-the-test-token"
User-Agent: "Faraday v1.10.3"
...I, [2023-09-27T21:55:31.957737 #79021]  INFO -- request: GET http://netbox.test/api/virtualization/cluster-types/1.json
I, [2023-09-27T21:55:31.957763 #79021]  INFO -- request: Authorization: "Token this-is-the-test-token"
User-Agent: "Faraday v1.10.3"
....I, [2023-09-27T21:55:31.964715 #79021]  INFO -- request: GET http://netbox.test/api/virtualization/virtual-machines.json?limit=42
I, [2023-09-27T21:55:31.964739 #79021]  INFO -- request: Authorization: "Token this-is-the-test-token"
User-Agent: "Faraday v1.10.3"
....

(etc)

The issue does not occur when tests are run on Ruby 3.2 with bundle exec rspec --seed 61562.

Solution

The root cause is from modifying the global configuration via NetboxClientRuby.configure in connection_spec.rb and netbox_spec.rb. These tests set a "logger" which bleeds over to other tests that are run after. Other configuration settings bleed over as well though their effect isn't observed.

The fix here is to reset all config changes before each test using the testing interface provided by Dry::Configurable. This change ensures that global configuration modifications from one test don't bleed into other tests.

https://dry-rb.org/gems/dry-configurable/1.0/testing/

This change ensures that global configuration modifications from one
test don't bleed into other tests, e.g. such as the logger which will
add noise to test output depending on the test order.

Uses the test interface from Dry::Configurable
https://dry-rb.org/gems/dry-configurable/1.0/testing/
Copy link
Member

@thde thde left a comment

Choose a reason for hiding this comment

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

LGTM

@thde thde merged commit b7434d2 into ninech:master Sep 28, 2023
2 checks passed
@thde
Copy link
Member

thde commented Sep 28, 2023

Thanks @rossta for the contribution!

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

Successfully merging this pull request may close these issues.

2 participants