Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

a method to help with testing/debugging #24

Open
wants to merge 1 commit into from

1 participant

@ryandotsmith

Hey!

I have found myself checking FakeWeb::Registry.uri_map a lot lately. Most of the time when I do this I am looking to make sure that I am stubbing the correct uris. This is necessary when I have helper methods generate stubs dynamically....

Anyways, I did a closure over uri_map. Not sure this is the most idiomatic way to handle this, but it led to some nice syntax.

Fakeweb::Registry.uri_map.inspect #=> [uri,uri]

Also, I am thinking of adding a counter the registry that show how many time the stubbed uri has been hit. Any thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 8, 2011
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 0 deletions.
  1. +7 −0 lib/fake_web/registry.rb
  2. +16 −0 test/test_registry.rb
View
7 lib/fake_web/registry.rb
@@ -8,6 +8,13 @@ def initialize
clean_registry
end
+ def uri_map
+ def @uri_map.inspect
+ self.keys.map(&:to_s)
+ end
+ @uri_map
+ end
+
def clean_registry
self.uri_map = Hash.new { |hash, key| hash[key] = {} }
end
View
16 test/test_registry.rb
@@ -0,0 +1,16 @@
+require 'test_helper'
+
+class TestUtility < Test::Unit::TestCase
+
+ def test_uri_map_inspect_returns_an_array_of_a_known_uri
+ FakeWeb.register_uri(:get,"http://google.com",:status => 200,:body => {})
+ assert_equal ["http://google.com/"], FakeWeb::Registry.instance.uri_map.inspect
+ end
+
+ def test_uri_map_inspect_returns_an_array_of_known_uris
+ FakeWeb.register_uri(:get,"http://google.com",:status => 200,:body => {})
+ FakeWeb.register_uri(:get,"http://heroku.com",:status => 200,:body => {})
+ assert_equal ["http://heroku.com/","http://google.com/"], FakeWeb::Registry.instance.uri_map.inspect
+ end
+
+end
Something went wrong with that request. Please try again.