Skip to content
Browse files

fix OpenCongress specs, should_not raise_error is the default expecta…

…tion
  • Loading branch information...
1 parent 9627a81 commit 3a599e7375af962627863ea320ae3466df4bd864 @jpmckinney jpmckinney committed Nov 7, 2012
Showing with 63 additions and 69 deletions.
  1. +32 −29 lib/gov_kit/open_congress/bill.rb
  2. +21 −20 lib/gov_kit/open_congress/person.rb
  3. +6 −16 spec/open_congress_spec.rb
  4. +4 −4 spec/transparency_data_spec.rb
View
61 lib/gov_kit/open_congress/bill.rb
@@ -123,46 +123,49 @@ def opencongress_users_opposing_bill_are_also
def self.parse_results(result)
bills = []
- result["bills"].each do |bill|
-
- these_recent_blogs = bill["recent_blogs"]
- blogs = []
-
- if these_recent_blogs
- these_recent_blogs.each do |trb|
- blogs << BlogPost.new(trb)
+ if Hash === result
+ result["bills"].each do |bill|
+ bill = bill['bill']
+
+ these_recent_blogs = bill["recent_blogs"]
+ blogs = []
+
+ if these_recent_blogs
+ these_recent_blogs.each do |trb|
+ blogs << BlogPost.new(trb)
+ end
end
- end
- bill["recent_blogs"] = blogs
+ bill["recent_blogs"] = blogs
- these_recent_news = bill["recent_news"]
- news = []
- if these_recent_news
- these_recent_news.each do |trb|
- news << NewsPost.new(trb)
+ these_recent_news = bill["recent_news"]
+ news = []
+ if these_recent_news
+ these_recent_news.each do |trb|
+ news << NewsPost.new(trb)
+ end
end
- end
- bill["recent_news"] = news
+ bill["recent_news"] = news
- these_co_sponsors = bill["co_sponsors"]
- co_sponsors = []
- if these_co_sponsors
- these_co_sponsors.each do |tcs|
- co_sponsors << Person.new(tcs)
+ these_co_sponsors = bill["co_sponsors"]
+ co_sponsors = []
+ if these_co_sponsors
+ these_co_sponsors.each do |tcs|
+ co_sponsors << Person.new(tcs)
+ end
end
- end
- bill["co_sponsors"] = co_sponsors
+ bill["co_sponsors"] = co_sponsors
-
- bill["sponsor"] = Person.new(bill["sponsor"]) if bill["sponsor"]
-
-
- bills << Bill.new(bill)
+
+ bill["sponsor"] = Person.new(bill["sponsor"]) if bill["sponsor"]
+
+ bills << Bill.new(bill)
+ end
end
+
bills
end
View
41 lib/gov_kit/open_congress/person.rb
@@ -105,30 +105,31 @@ def opencongress_users_opposing_person_are_also
def self.parse_results(result)
people = []
- result["people"].each do |person|
-
- these_recent_blogs = person["recent_blogs"]
- blogs = []
- these_recent_blogs.each do |trb|
- blogs << BlogPost.new(trb)
- end
+ if Hash === result
+ result["people"].each do |person|
+ person = person['person']
+
+ these_recent_blogs = person["recent_blogs"]
+ blogs = []
+ these_recent_blogs.each do |trb|
+ blogs << BlogPost.new(trb)
+ end
+ person["recent_blogs"] = blogs
- person["recent_blogs"] = blogs
+ these_recent_news = person["recent_news"]
+ news = []
+ these_recent_news.each do |trb|
+ news << NewsPost.new(trb)
+ end
+ person["person_stats"] = PersonStat.new(person["person_stats"]) if person["person_stats"]
- these_recent_news = person["recent_news"]
- news = []
- these_recent_news.each do |trb|
- news << NewsPost.new(trb)
+ person["recent_news"] = news
+
+ people << Person.new(person)
end
-
- person["person_stats"] = PersonStat.new(person["person_stats"]) if person["person_stats"]
-
- person["recent_news"] = news
-
- people << Person.new(person)
- end
-
+ end
+
people
end
View
22 spec/open_congress_spec.rb
@@ -38,19 +38,15 @@ module GovKit::OpenCongress
describe Person do
context "#find" do
it "should find a specific person" do
- lambda do
- @person = Person.find(:district => 1, :state => "FL").first
- end.should_not raise_error
+ @person = Person.find(:district => 1, :state => "FL").first
@person.should be_an_instance_of(Person)
@person.firstname.should == "Jeff"
@person.lastname.should == "Miller"
end
it "should return an empty array when no person fits the criteria" do
- lambda do
- @person = Person.find(:district => 0, :state => "ZZ")
- end.should_not raise_error
+ @person = Person.find(:district => 0, :state => "ZZ")
@person.should be_an_instance_of(Array)
@person.empty?.should be_true
@@ -59,9 +55,7 @@ module GovKit::OpenCongress
context "#most blogged representatives this week" do
it "should find reps" do
- lambda do
- @person = Person.most_blogged_representatives_this_week.first
- end.should_not raise_error
+ @person = Person.most_blogged_representatives_this_week.first
@person.should be_an_instance_of(Person)
@person.firstname.should == "Jeff"
@@ -73,13 +67,11 @@ module GovKit::OpenCongress
describe Bill do
context "#find" do
it "should find a specific bill" do
- lambda do
- @bill = Bill.find(:number => 501).first
- end.should_not raise_error
+ @bill = Bill.find(:number => 501).first
@bill.should be_an_instance_of(Bill)
@bill.number.should == 501
- @bill.bill_type.should == "h"
+ @bill.bill_type.should == (FakeWeb.allow_net_connect? ? "hr" : "h")
end
it "should return an empty array when no bill fits the criteria" do
@@ -92,9 +84,7 @@ module GovKit::OpenCongress
context "#most blogged bills this week" do
it "should find specific bills" do
- lambda do
- @bill = Bill.most_blogged_bills_this_week.first
- end.should_not raise_error
+ @bill = Bill.most_blogged_bills_this_week.first
@bill.should be_an_instance_of(Bill)
@bill.number.should == 2678
View
8 spec/transparency_data_spec.rb
@@ -36,7 +36,7 @@ module GovKit::TransparencyData
@contributions = Contribution.search
end.should_not raise_error
- @contributions.length.should eql(8) # 1000 unless using FakeWeb
+ @contributions.length.should eql(FakeWeb.allow_net_connect? ? 1000 : 8)
@contributions[0].contributor_city.should eql("ANCHORAGE")
end
end
@@ -56,7 +56,7 @@ module GovKit::TransparencyData
@entities = Entity.search( "nancy+pelosi" )
end.should_not raise_error
- @entities.length.should eql(1) # 2 unless using FakeWeb
+ @entities.length.should eql(FakeWeb.allow_net_connect? ? 2 : 1)
end
end
end
@@ -68,7 +68,7 @@ module GovKit::TransparencyData
@records = LobbyingRecord.search
end.should_not raise_error
- @records.length.should eql(5) # 1000 unless using FakeWeb
+ @records.length.should eql(FakeWeb.allow_net_connect? ? 1000 : 5)
@records[0].lobbyists[0].lobbyist_name.should eql('Dunn, Jennifer B')
end
end
@@ -81,7 +81,7 @@ module GovKit::TransparencyData
@records = Grant.search
end.should_not raise_error
- @records.length.should eql(3) # 1000 unless using FakeWeb
+ @records.length.should eql(FakeWeb.allow_net_connect? ? 1000 : 3)
@records[0].project_description.should eql('NATIONAL FLOOD INSURANCE PROGRAM')
end
end

0 comments on commit 3a599e7

Please sign in to comment.
Something went wrong with that request. Please try again.