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

Improve URL testing #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexWayfer
Copy link
Contributor

Please, don't test private methods via send.

attr_accessor :body

def initialize(_config); end

def get(_url)
def get(url)
self.class.last_url = url
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is a thread-safe implementation. If you want to get rid of the send methods in the tests I might recommend a spy that you can later assert on, some kind of UrlAssertHTTPTestClient that would expose the information you want, or possibly extracting the URL construction into a separate object that can be tested in isolation.

Overall, I don't know that it really matters though. There is no behavioral change in this PR. The send method is certainly not a good practice, but it's contained within the test for its class only - so I don't particularly see it as a big problem. Under normal circumstances we might expose this method publicly, but I don't want to make this part of the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's rewrited with mocks! What do you think now?

Please, don't test private methods via `send`.

Use `Minitest::Mock`.
Copy link
Owner

@panthomakos panthomakos left a comment

Choose a reason for hiding this comment

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

I don't think the elimination of send in these specs is worth the extra work in maintaining and understanding the mocks.

:call, "/maps/api/timezone/json?#{params.join('&')}", %w[123 123]
)

mine.stub :url, url_method do
Copy link
Owner

Choose a reason for hiding this comment

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

You still end up asserting on the private method call here so I don't see the benefit of this approach. The original spec (w/o the mocks) is easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you wish. Mocks is common practice. They're more complex in Minitest than in RSpec, yes.

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.

2 participants