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

Cleanup the number of helper methods that are available for all specs #3173

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Sep 29, 2023

What does this PR do?

Clean up our spec_helper file and reduce the number of helpers included for all specs. Also, delete duplicated shared_exmaples, and unused custom matchers.

If a few specs need a helper, we should first require the spec helper directly, rather than adding as part of the global available helpers. Once we identify that a helper is widely used we can promote it to be part of all the specs. This will keep the spec_helper.rb lean, and it would be easier to understand what is that all the specs need in order to work properly.

Motivation:

Additional Notes:

How to test the change?

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@github-actions github-actions bot added the dev/testing Involves testing processes (e.g. RSpec) label Sep 29, 2023
@GustavoCaso GustavoCaso force-pushed the spec-helpers-cleanup branch 2 times, most recently from fe31e2d to 41e83b1 Compare September 29, 2023 14:20
@GustavoCaso GustavoCaso changed the title Cleanup the number of helper methods that are available for all Cleanup the number of helper methods that are available for all specs Sep 29, 2023
@GustavoCaso GustavoCaso force-pushed the spec-helpers-cleanup branch from 41e83b1 to b087037 Compare October 2, 2023 08:30
@GustavoCaso GustavoCaso marked this pull request as ready for review October 2, 2023 09:05
@GustavoCaso GustavoCaso requested review from a team as code owners October 2, 2023 09:05
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

👍 Seems reasonable, thanks for the cleanup!

@@ -1,7 +1,7 @@
require 'stringio'
Copy link
Member

Choose a reason for hiding this comment

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

Minor / probably not for this PR: This "shared" helper actually only gets used by two files in spec/datadog/core/environment/ -- I think we could perhaps move it there? (And even only include the module in those specs, rather than make it available to all others)

Copy link
Member Author

Choose a reason for hiding this comment

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

That is already the case @ivoanjo
image

https://github.com/DataDog/dd-trace-rb/pull/3173/files#diff-89eebfcbc0f14b6d989517837ca1e94fce4e2ce9a03233641cd936f2b8d2ed94L65

I guess the last remaining thing is move it to the spec/datadog/core/environment/ folder

Copy link
Member

Choose a reason for hiding this comment

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

That is already the case @ivoanjo

Well, not entirely. As long as you require those specs, the helper will get required and made available for every other spec. But now that I look at them a bit closer, I think we'd need to to further changes if we wanted them to not "leak" to other specs.

So maybe just the move? ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

I see want you mean 😄

Copy link
Member Author

@GustavoCaso GustavoCaso Oct 2, 2023

Choose a reason for hiding this comment

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

I'll explore what we can do to cleanup the global helpers

Comment on lines 63 to 72
before do
allow(Datadog).to receive(:logger).and_return(double)
logger = double(Datadog::Core::Logger)
allow(logger).to receive(:debug?).and_return true
allow(logger).to receive(:debug)
allow(logger).to receive(:info)
allow(logger).to receive(:warn)
allow(logger).to receive(:error)

allow(Datadog).to receive(:logger).and_return(logger)
end
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I'm curious -- why was this change needed? Was the logger being noisy and this was changed to silence it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The change was done to replicate the shared example in spec/datadog/tracing/buffer_spec.rb. My two cents teel me that the logger in one of the shared examples was mocking fewer methods and couldn't be used for the spec/datadog/tracing/buffer_spec.rb file, so it got copied and modified to make it pass for that case.

@@ -22,169 +23,6 @@
end
end

RSpec.shared_examples 'thread-safe buffer' do
Copy link
Member

Choose a reason for hiding this comment

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

Weird that this was already duplicated in buffer/shared_examples...

@GustavoCaso GustavoCaso merged commit 6a3a9e7 into master Oct 2, 2023
@GustavoCaso GustavoCaso deleted the spec-helpers-cleanup branch October 2, 2023 12:40
@github-actions github-actions bot added this to the 1.15.0 milestone Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/testing Involves testing processes (e.g. RSpec)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants