[openstreetmap/openstreetmap-website] Use Webmock to intercept http requests in tests (#1350)

Andy Allan notifications at github.com
Tue Nov 1 11:16:45 UTC 2016

gravitystorm commented on this pull request.

> @@ -160,23 +161,18 @@ def assert_no_missing_translations(msg = "")
     # execute a block with a given set of HTTP responses stubbed
     def with_http_stubs(stubs_file)
-      http_client_save = OSM.http_client
-      begin
-        stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__))
+      stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__))
+      stubs.each do |url, response|
+        stub_request(:get, Regexp.new(Regexp.quote(url))).to_return(:status => response["code"], :body => response["body"])

I'd prefer to build the actual URLs to stub, rather than regexping. The previous approach sidestepped the issue of domains entirely so they aren't in the fixtures files. Effectively the mocking was via paths alone, but I couldn't see a way to replicate that in webmock since it expects full urls with protocols and hostnames too, so I went with Regexps.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20161101/5fc65f6d/attachment.html>

More information about the rails-dev mailing list