Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow tests to run against live URLs

  • Loading branch information...
commit f545b8b60e1c4b8ffc3d0aba278d1100e4c81b8f 1 parent 07ac19a
@jpmckinney jpmckinney authored
View
21 spec/follow_the_money_spec.rb
@@ -12,18 +12,19 @@ module GovKit::FollowTheMoney
describe GovKit::FollowTheMoney do
before(:all) do
- base_uri = GovKit::FollowTheMoneyResource.base_uri.gsub(/\./, '\.')
+ unless FakeWeb.allow_net_connect?
+ base_uri = GovKit::FollowTheMoneyResource.base_uri.gsub(/\./, '\.')
- urls = [
- ['/base_level\.industries\.list\.php\?.*page=0', 'business-page0.response'],
- ['/base_level\.industries\.list\.php\?.*page=1', 'business-page1.response'],
- ['/candidates\.contributions\.php\?imsp_candidate_id=111933', 'contribution.response'],
- ['/candidates\.contributions\.php\?imsp_candidate_id=0', 'unauthorized.response'],
- ]
+ urls = [
+ ['/base_level\.industries\.list\.php\?.*page=0', 'business-page0.response'],
+ ['/base_level\.industries\.list\.php\?.*page=1', 'business-page1.response'],
+ ['/candidates\.contributions\.php\?imsp_candidate_id=111933', 'contribution.response'],
+ ['/candidates\.contributions\.php\?imsp_candidate_id=0', 'unauthorized.response'],
+ ]
- urls.each do |u|
- FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'follow_the_money', u[1]))
- # puts "registered #{base_uri}#{u[0]}"
+ urls.each do |u|
+ FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'follow_the_money', u[1]))
+ end
end
end
View
34 spec/open_congress_spec.rb
@@ -4,24 +4,22 @@ module GovKit::OpenCongress
describe GovKit::OpenCongress do
before(:all) do
@oc_objs = [Bill, Person]
- base_uri = "http://api.opencongress.org/"
-
- # An array of uris and filenames
- # Use FakeWeb to intercept net requests;
- # if a requested uri matches one of the following,
- # then return the contents of the corresponding file
- # as the result.
- urls = [
- [ "people?format=json&district=1&state=FL", "fl01.response" ],
- [ "people?format=json&district=0&state=ZZ", "empty.response" ],
- [ "most_blogged_representatives_this_week?format=json", "person.response" ],
- [ "bills?format=json&number=0", "empty.response" ],
- [ "bills?format=json&number=501", "501.response" ],
- [ "most_blogged_bills_this_week?format=json", "bill.response" ]
- ]
-
- urls.each do |u|
- FakeWeb.register_uri(:get, "#{base_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'open_congress', u[1]))
+
+ unless FakeWeb.allow_net_connect?
+ base_uri = "http://api.opencongress.org/"
+
+ urls = [
+ [ "people?format=json&district=1&state=FL", "fl01.response" ],
+ [ "people?format=json&district=0&state=ZZ", "empty.response" ],
+ [ "most_blogged_representatives_this_week?format=json", "person.response" ],
+ [ "bills?format=json&number=0", "empty.response" ],
+ [ "bills?format=json&number=501", "501.response" ],
+ [ "most_blogged_bills_this_week?format=json", "bill.response" ]
+ ]
+
+ urls.each do |u|
+ FakeWeb.register_uri(:get, "#{base_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'open_congress', u[1]))
+ end
end
end
View
100 spec/open_states_spec.rb
@@ -11,55 +11,57 @@
module GovKit::OpenStates
describe GovKit::OpenStates do
before(:all) do
- base_uri = GovKit::OpenStatesResource.base_uri.gsub(/\./, '\.')
-
- # An array of uris and filenames
- # Use FakeWeb to intercept net requests;
- # if a requested uri matches one of the following,
- # then return the contents of the corresponding file
- # as the result.
- urls = [
- ['/bills/ca/20092010/AB667/', 'bill.response'],
- ['/bills/\?.*q=cooperatives.*', 'bill_query.response'],
- ['/bills/\?.*state=tx.*', 'bill_query.response'],
- ['/bills/\?.*q=professions.*', 'bill.response'],
- ['/bills/latest/\?', 'bill_query.response'],
- ['/legislators/2462/\?', 'legislator.response'],
- ['/legislators/410/\?', '410.response'],
- ['/legislators/401/\?', '401.response'],
- ['/legislators/404/\?', '404.response'],
- ['/legislators/\?.*state=zz.*', '404.response'],
- ['/legislators/\?.*state=ca.*', 'legislator.response'],
- ['/committees/MDC000012/', 'committee_find.response'],
- ['/committees/\?.*state=md', 'committee_query.response'],
- ['/metadata/ca/\?', 'state.response']
- ]
-
- # First convert each of the uri strings above into regexp's before
- # passing them on to register_uri.
- #
- # Internally, before checking if a new uri string matches one of the registered uri's,
- # FakeWeb normalizes it by parsing it with URI.parse(string), and then
- # calling URI.normalize on the resulting URI. This appears to reorder any
- # query parameters alphabetically by key.
- #
- # So the uri
- # http://openstates.sunlightlabs.com/api/v1/legislators/?state=zz&output=json&apikey=
- # would actually not match a registered uri of
- # ['/legislators/\?state=zz', '404.response'],
- # or
- # ['/legislators/\?state=zz*', '404.response'],
- # or even
- # ['/legislators/\?state=zz&output=json&apikey=', '404.response'],
- #
- # But it would match a registered uri of
- # ['/legislators/\?apikey=&output=json&state=zz', '404.response'],
- # or
- # ['/legislators/\?(.*)state=zz(.*)', '404.response'],
-
-
- urls.each do |u|
- FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'open_states', u[1]))
+ unless FakeWeb.allow_net_connect?
+ base_uri = GovKit::OpenStatesResource.base_uri.gsub(/\./, '\.')
+
+ # An array of uris and filenames
+ # Use FakeWeb to intercept net requests;
+ # if a requested uri matches one of the following,
+ # then return the contents of the corresponding file
+ # as the result.
+ urls = [
+ ['/bills/ca/20092010/AB667/', 'bill.response'],
+ ['/bills/\?.*q=cooperatives.*', 'bill_query.response'],
+ ['/bills/\?.*state=tx.*', 'bill_query.response'],
+ ['/bills/\?.*q=professions.*', 'bill.response'],
+ ['/bills/latest/\?', 'bill_query.response'],
+ ['/legislators/2462/\?', 'legislator.response'],
+ ['/legislators/410/\?', '410.response'],
+ ['/legislators/401/\?', '401.response'],
+ ['/legislators/404/\?', '404.response'],
+ ['/legislators/\?.*state=zz.*', '404.response'],
+ ['/legislators/\?.*state=ca.*', 'legislator.response'],
+ ['/committees/MDC000012/', 'committee_find.response'],
+ ['/committees/\?.*state=md', 'committee_query.response'],
+ ['/metadata/ca/\?', 'state.response']
+ ]
+
+ # First convert each of the uri strings above into regexp's before
+ # passing them on to register_uri.
+ #
+ # Internally, before checking if a new uri string matches one of the registered uri's,
+ # FakeWeb normalizes it by parsing it with URI.parse(string), and then
+ # calling URI.normalize on the resulting URI. This appears to reorder any
+ # query parameters alphabetically by key.
+ #
+ # So the uri
+ # http://openstates.sunlightlabs.com/api/v1/legislators/?state=zz&output=json&apikey=
+ # would actually not match a registered uri of
+ # ['/legislators/\?state=zz', '404.response'],
+ # or
+ # ['/legislators/\?state=zz*', '404.response'],
+ # or even
+ # ['/legislators/\?state=zz&output=json&apikey=', '404.response'],
+ #
+ # But it would match a registered uri of
+ # ['/legislators/\?apikey=&output=json&state=zz', '404.response'],
+ # or
+ # ['/legislators/\?(.*)state=zz(.*)', '404.response'],
+
+
+ urls.each do |u|
+ FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'open_states', u[1]))
+ end
end
end
View
23 spec/search_engines_spec.rb
@@ -3,19 +3,16 @@
module GovKit::SearchEngines
describe GovKit::SearchEngines do
before(:all) do
- google_news_uri = "http://news.google.com/"
-
- # An array of uris and filenames
- # Use FakeWeb to intercept net requests;
- # if a requested uri matches one of the following,
- # then return the contents of the corresponding file
- # as the result.
- urls = [
- [ "news?q=congress&output=rss&num=50", "google_news.response" ]
- ]
-
- urls.each do |u|
- FakeWeb.register_uri(:get, "#{google_news_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'search_engines', u[1]))
+ unless FakeWeb.allow_net_connect?
+ google_news_uri = "http://news.google.com/"
+
+ urls = [
+ [ "news?q=congress&output=rss&num=50", "google_news.response" ]
+ ]
+
+ urls.each do |u|
+ FakeWeb.register_uri(:get, "#{google_news_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'search_engines', u[1]))
+ end
end
end
View
1  spec/spec_helper.rb
@@ -25,6 +25,7 @@ def rp(*args)
end
end
+# Set to true to run tests against the live URLs
FakeWeb.allow_net_connect = false
FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
View
28 spec/transparency_data_spec.rb
@@ -12,19 +12,21 @@ module GovKit::TransparencyData
describe GovKit::TransparencyData do
before(:all) do
- base_uri = GovKit::TransparencyDataResource.base_uri.gsub(/\./, '\.')
-
- urls = [
- ['/contributions.json\?', 'contributions.response'],
- ['/lobbying.json\?', 'lobbyists_find_all.response'],
- ['/grants.json\?', 'grants_find_all.response'],
- ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=$', 'entities_search.response'],
- ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=harry%20pelosi', 'entities_search_limit_0.response'],
- ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=nancy%2Bpelosi', 'entities_search_limit_1.response']
- ]
-
- urls.each do |u|
- FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'transparency_data', u[1]))
+ unless FakeWeb.allow_net_connect?
+ base_uri = GovKit::TransparencyDataResource.base_uri.gsub(/\./, '\.')
+
+ urls = [
+ ['/contributions.json\?', 'contributions.response'],
+ ['/lobbying.json\?', 'lobbyists_find_all.response'],
+ ['/grants.json\?', 'grants_find_all.response'],
+ ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=$', 'entities_search.response'],
+ ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=harry%20pelosi', 'entities_search_limit_0.response'],
+ ['/entities.json\?apikey=YOUR_OPENSTATES_API_KEY&search=nancy%2Bpelosi', 'entities_search_limit_1.response']
+ ]
+
+ urls.each do |u|
+ FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'transparency_data', u[1]))
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.