spec/twitter_auth/dispatcher/oauth_spec.rb in mbleigh-twitter-auth-0.1.3 vs spec/twitter_auth/dispatcher/oauth_spec.rb in mbleigh-twitter-auth-0.1.5
- old
+ new
@@ -43,9 +43,24 @@
it 'should append .json to the path if no extension is provided' do
@dispatcher.request(:get, '/fake').should == @dispatcher.request(:get, '/fake.json')
end
+ it "should raise a TwitterAuth::Dispatcher::Error if response code isn't 200" do
+ FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['401', 'Unauthorized'])
+ lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error)
+ end
+
+ it 'should set the error message to the JSON message' do
+ FakeWeb.register_uri('https://twitter.com:443/bad_response.json', :string => {'error' => 'bad response'}.to_json, :status => ['401', 'Unauthorized'])
+ lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
+ end
+
+ it 'should set the error message to the XML message' do
+ FakeWeb.register_uri('https://twitter.com:443/bad_response.xml', :string => "<hash>\n<request>/bad_response.xml</request>\n<error>bad response</error>\n</hash>", :status => ['401', 'Unauthorized'])
+ lambda{@dispatcher.request(:get, '/bad_response')}.should raise_error(TwitterAuth::Dispatcher::Error, 'bad response')
+ end
+
it 'should work with verb methods' do
@dispatcher.get('/fake').should == @dispatcher.request(:get, '/fake')
end
end
end