Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions test/timezone/lookup/test_google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,48 @@ def test_google_request_denied_read_lat_long_coordinates

def test_url_non_enterprise
Timecop.freeze(Time.at(1_433_347_661)) do
result = lookup.send(:url, '123', '123')
mine = lookup('{ "status": "OK" }')

params = {
'location' => '123%2C123',
'timestamp' => '1433347661',
'key' => 'MTIzYWJj'
}.map { |k, v| "#{k}=#{v}" }

assert_equal "/maps/api/timezone/json?#{params.join('&')}", result
url_method = Minitest::Mock.new
url_method.expect(
: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.

mine.lookup('123', '123')
end

url_method.verify
end
end

def test_url_enterprise
mine = lookup { |c| c.client_id = '123&asdf' }
mine = lookup('{ "status": "OK" }') { |c| c.client_id = '123&asdf' }

Timecop.freeze(Time.at(1_433_347_661)) do
result = mine.send(:url, '123', '123')
params = {
'location' => '123%2C123',
'timestamp' => '1433347661',
'client' => '123%26asdf',
'signature' => 'B1TNSSvIw9Wvf_ZjjW5uRzGm4F4='
}.map { |k, v| "#{k}=#{v}" }

assert_equal "/maps/api/timezone/json?#{params.join('&')}", result
url_method = Minitest::Mock.new
url_method.expect(
:call, "/maps/api/timezone/json?#{params.join('&')}", %w[123 123]
)

mine.stub :url, url_method do
mine.lookup('123', '123')
end

url_method.verify
end
end

Expand Down