ruby-on-railsrubyfakeweb

List of URIs registered to FakeWeb


Is there a way to get a list of registered URIs in FakeWeb? When I register one like:

FakeWeb.register_uri(:get, url, body: expected_response)

It seems like it should be available somewhere since it keeps track of it internally, but I can't track it down externally. Something like FakeWeb.registered_uris, but obviously that doesn't work.


Solution

  • Try

    FakeWeb::Registry.instance.uri_map
    

    This returns a nested hash with FakeWeb::Responder objects.

    When you register a uri with #register_uri, FakeWeb creates a FakeWeb::Responder which holds the uri, which is then stored within the FakeWeb::Registry singleton.

    You finally have to iterate the result map and get the uri's out of it:

    FakeWeb::Registry.instance.uri_map.map { |_, v| v.map { |_, w| w } }.flatten.collect { |e| e.uri }.uniq
    

    Hope this helps.