1
0
Fork 0
mirror of https://github.com/nov/fb_graph2 synced 2023-03-27 23:22:15 -04:00

node spec

This commit is contained in:
nov 2014-05-28 11:41:04 +09:00
parent 848ad65fbe
commit 95f699fb7c
5 changed files with 52 additions and 1 deletions

View file

@ -84,7 +84,8 @@ module FbGraph2
raise response.body
end
rescue MultiJson::DecodeError
raise Exception.new(response.status, "Unparsable Response: #{response.body}")
# TODO: better exception structure
raise response.body
end
end
end

View file

@ -9,6 +9,14 @@ describe FbGraph2::Node do
it { should_not respond_to :register_attributes }
it { should_not respond_to :registered_attributes }
it { should_not respond_to :registered_attributes= }
describe '.fetch' do
it 'should call API' do
expect do
klass.fetch 'foo'
end.to request_to '/foo'
end
end
end
context 'instance' do
@ -25,5 +33,35 @@ describe FbGraph2::Node do
before { instance.authenticate 'access_token' }
its(:access_token) { should == 'access_token' }
end
describe '#handle_response' do
context 'when error' do
context 'when valid json' do
it 'should raise' do
expect do
mock_graph :get, 'identifier', 'error/400/2500', status: 400 do
instance.fetch
end
end.to raise_error { |e|
e.should be_instance_of RuntimeError
e.message.should == mock_json('error/400/2500')
}
end
end
context 'when invalid json' do
it 'should raise' do
expect do
mock_graph :get, 'identifier', 'error/invalid_format', status: 400 do
instance.fetch
end
end.to raise_error { |e|
e.should be_instance_of RuntimeError
e.message.should == mock_json('error/invalid_format')
}
end
end
end
end
end
end

View file

@ -0,0 +1,7 @@
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}

View file

@ -0,0 +1 @@
NOT FOUND

View file

@ -22,6 +22,10 @@ module MockGraph
end
end
def mock_json(response_path)
response_for(response_path)[:body].read
end
def request_to(path, method = :get)
raise_error { |e|
e.should be_instance_of WebMock::NetConnectNotAllowedError