spec/api.rb in fcc_reboot-0.1 vs spec/api.rb in fcc_reboot-0.2.1
- old
+ new
@@ -1,7 +1,25 @@
require 'helper'
+describe FccReboot do
+ after do
+ FccReboot.reset
+ end
+
+ describe ".respond_to?" do
+ it "should return true if method exists" do
+ FccReboot.respond_to?(:client, true).should be_true
+ end
+ end
+
+ describe ".client" do
+ it "should be a FccReboot::Client" do
+ FccReboot.client.should be_a FccReboot::Client
+ end
+ end
+end
+
describe FccReboot, ".broadband_test" do
before do
stub_request(:get, 'http://data.fcc.gov/api/speedtest/find').
with(:query => {:format => 'json', :latitude => '38.0', :longitude => '-77.5'}).
to_return(:body => fixture('broadband_test.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
@@ -57,22 +75,22 @@
FccReboot.frn_getlist(:stateCode => 'IL', :multi => true)
a_request(:get, 'http://data.fcc.gov/api/frn/getList').
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'Yes'}).
should have_been_made
end
-
+
it "should request the correct resource" do
FccReboot.frn_getlist(:stateCode => 'IL', :multi => false)
a_request(:get, 'http://data.fcc.gov/api/frn/getList').
with(:query => {:format => 'json', :stateCode => 'IL', :multi => 'No'}).
should have_been_made
end
it "should return the correct results" do
services = FccReboot.frn_getlist(:stateCode => 'IL', :multi => false)
- services.should be_a Hash
- services["Frns"]["Frn"].first["frn"].should == '0017855545'
+ services.should be_a Array
+ services.first["frn"].should == '0017855545'
end
end
describe FccReboot, ".frn_getinfo" do
before do
@@ -85,15 +103,15 @@
FccReboot.frn_getinfo(:frn => '0017855545')
a_request(:get, 'http://data.fcc.gov/api/frn/getInfo').
with(:query => {:format => 'json', :frn => '0017855545'}).
should have_been_made
end
-
+
it "should return the correct results" do
services = FccReboot.frn_getinfo(:frn => '0017855545')
services.should be_a Hash
- services["Info"]["frn"].should == '0017855545'
+ services["frn"].should == '0017855545'
end
end
describe FccReboot, ".get_spectrum_bands" do
before do
@@ -138,13 +156,17 @@
end
describe FccReboot, ".get_licenses" do
before do
@query = {:searchValue => 'Verizon%20Wireless', :format =>'json'}
+ @bad_query = {:searchValue => 'some name', :format =>'json'}
stub_request(:get, 'http://data.fcc.gov/api/license-view/basicSearch/getLicenses').
with(:query => @query).
to_return(:body => fixture('license-view-get-licenses.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
+ stub_request(:get, 'http://data.fcc.gov/api/license-view/basicSearch/getLicenses').
+ with(:query => @bad_query).
+ to_return(:body => fixture('license-view-get-licenses-error.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
end
it "should request the correct resource" do
FccReboot.get_licenses(@query)
a_request(:get, 'http://data.fcc.gov/api/license-view/basicSearch/getLicenses').
@@ -155,15 +177,21 @@
it "should return the correct results" do
licenses = FccReboot.get_licenses(@query)
licenses.should be_a Array
licenses[0]["licenseID"].should == '2300007967'
end
+
+ it "should return the correct results" do
+ licenses = FccReboot.get_licenses(@bad_query)
+ licenses.should be_a Hash
+ licenses["Errors"]["Err"][0]["code"].should == '110'
+ end
end
describe FccReboot, ".get_common_names" do
before do
- @query = {:commonName => 'Sprint%20Nextel', :limit => '10'}
+ @query = {:commonName => 'Sprint%20Nextel', :limit => '10', :format => 'json'}
@url = 'http://data.fcc.gov/api/license-view/licenses/getCommonNames'
stub_request(:get, @url).
with(:query => @query).
to_return(:body => fixture('license-view-get-common-names.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
end
@@ -182,10 +210,10 @@
end
end
describe FccReboot, ".get_statuses" do
before do
- @query = {:commonName => 'Sprint%20Nextel', :limit => '10'}
+ @query = {:commonName => 'Sprint%20Nextel', :limit => '10', :format => 'json'}
@url = 'http://data.fcc.gov/api/license-view/licenses/getStatuses'
stub_request(:get, @url).
with(:query => @query).
to_return(:body => fixture('license-view-get-statuses.json'), :headers => {'Content-Type' => 'text/json; charset=utf-8'})
end