From ec6a82d4032470516445df52d90fe67ddce71323 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Fri, 28 Jan 2011 19:56:11 -0500 Subject: [PATCH] Used vcr to record tests and save the results (remember to sanitize the cassettes of your oauth credentials) --- spec/feature_spec.rb | 16 ++++--- vcr/cassettes/feature_valid.yml | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 vcr/cassettes/feature_valid.yml diff --git a/spec/feature_spec.rb b/spec/feature_spec.rb index 9e95018..838c1a4 100644 --- a/spec/feature_spec.rb +++ b/spec/feature_spec.rb @@ -2,16 +2,22 @@ describe "Client" do before do - SimpleGeo::Client.set_credentials 'token', 'secret' + SimpleGeo::Client.set_credentials('token', 'secret') end it "should return a feature when requesting it using the correct handle" do - @feature = SimpleGeo::Client.get_feature("SG_4ahRExz3iKlEjoeSZk7b9G_40.728714_-73.992082") - @feature.properties[:name].should == 'The Public Theater' + VCR.use_cassette("feature_valid", + :record => :new_episodes) do + @feature = SimpleGeo::Client.get_feature("SG_4ahRExz3iKlEjoeSZk7b9G_40.728714_-73.992082") + @feature.properties[:name].should == 'The Public Theater' + end end - + it "should throw an errorwhen requesting a feature with an invalid handle" do - expect{SimpleGeo::Client.get_feature("badly-formed-handle")}.to raise_error + VCR.use_cassette("feature_valid", + :record => :new_episodes) do + expect{SimpleGeo::Client.get_feature("badly-formed-handle")}.to raise_error(SimpleGeo::SimpleGeoError) + end end end \ No newline at end of file diff --git a/vcr/cassettes/feature_valid.yml b/vcr/cassettes/feature_valid.yml new file mode 100644 index 0000000..bdb23dc --- /dev/null +++ b/vcr/cassettes/feature_valid.yml @@ -0,0 +1,77 @@ +--- +- !ruby/struct:VCR::HTTPInteraction + request: !ruby/struct:VCR::Request + method: :get + uri: http://api.simplegeo.com:80/1.0/features/SG_4ahRExz3iKlEjoeSZk7b9G_40.728714_-73.992082.json + body: + headers: + user-agent: + - SimpleGeo Ruby Client v0.1.0 (OAuth gem v0.4.4) + authorization: + - OAuth oauth_consumer_key="", oauth_nonce="", oauth_signature="", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1296262263", oauth_version="1.0" + response: !ruby/struct:VCR::Response + status: !ruby/struct:VCR::ResponseStatus + code: 200 + message: OK + headers: + content-type: + - application/json + connection: + - Close + date: + - Sat, 29 Jan 2011 00:51:03 GMT + server: + - gate/0.1.152 + x-request-id: + - Vxm4Fmw4Znnjdvz1/wB6o4 + x-sg-host: + - production-api-a76a26cd.ck.simplegeo.com + x-response-time: + - "18" + content-length: + - "587" + x-timing-stats: + - "{\"auth\":0,\"PushPin\":6,\"Places\":16}" + vary: + - Accept-Encoding + body: | + {"geometry":{"type":"Point","coordinates":[-73.992082,40.728714]},"type":"Feature","id":"SG_4ahRExz3iKlEjoeSZk7b9G_40.728714_-73.992082@1294177022","properties":{"province":"NY","city":"New York","name":"The Public Theater","tags":["theatrical","company","production"],"country":"US","phone":"+1 212 539 8500","href":"http://api.simplegeo.com/1.0/features/SG_4ahRExz3iKlEjoeSZk7b9G_40.728714_-73.992082@1294177022.json","address":"425 Lafayette St","owner":"simplegeo","postcode":"10003","classifiers":[{"category":"Arts & Performance","type":"Entertainment","subcategory":"Theater"}]}} + + http_version: "1.1" +- !ruby/struct:VCR::HTTPInteraction + request: !ruby/struct:VCR::Request + method: :get + uri: http://api.simplegeo.com:80/1.0/features/badly-formed-handle.json + body: + headers: + user-agent: + - SimpleGeo Ruby Client v0.1.0 (OAuth gem v0.4.4) + authorization: + - OAuth oauth_consumer_key="", oauth_nonce="", oauth_signature="%%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1296262328", oauth_version="1.0" + response: !ruby/struct:VCR::Response + status: !ruby/struct:VCR::ResponseStatus + code: 400 + message: Bad Request + headers: + connection: + - Close + content-type: + - application/json + x-sg-host: + - production-api-a74b07cd.ck.simplegeo.com + x-request-id: + - 4JsWdBDPWv0XiRrAsXY09o + server: + - gate/0.1.152 + date: + - Sat, 29 Jan 2011 00:52:08 GMT + content-length: + - "40" + x-response-time: + - "3" + x-timing-stats: + - "{\"auth\":3}" + body: | + {"code":400,"message":"Invalid handle"} + + http_version: "1.1"