-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: master
Are you sure you want to change the base?
Conversation
test/http_test_client.rb
Outdated
attr_accessor :body | ||
|
||
def initialize(_config); end | ||
|
||
def get(_url) | ||
def get(url) | ||
self.class.last_url = url |
There was a problem hiding this 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 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.
There was a problem hiding this comment.
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`.
760f4fd
to
1c9bfca
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Please, don't test private methods via
send
.