test/test_handler.rb in rest-graph-1.5.0 vs test/test_handler.rb in rest-graph-1.6.0
- old
+ new
@@ -5,16 +5,16 @@
require File.dirname(__FILE__) + '/common'
end
describe RestGraph do
after do
- reset_webmock
+ WebMock.reset_webmock
RR.verify
end
describe 'log handler' do
- it 'would log whenever doing network request' do
+ should 'log whenever doing network request' do
stub_request(:get, 'https://graph.facebook.com/me').
to_return(:body => '{}')
mock(Time).now{ 666 }
mock(Time).now{ 999 }
@@ -28,28 +28,29 @@
end
end
describe 'with Graph API' do
before do
- @id = lambda{ |obj| obj }
+ @id = lambda{ |obj, url| obj }
@error = '{"error":{"type":"Exception","message":"(#2500)"}}'
@error_hash = RestGraph.json_decode(@error)
stub_request(:get, 'https://graph.facebook.com/me').
to_return(:body => @error)
end
- it 'would call error_handler if error occurred' do
+ should 'call error_handler if error occurred' do
RestGraph.new(:error_handler => @id).get('me').should == @error_hash
end
- it 'would raise ::RestGraph::Error in default error_handler' do
+ should 'raise ::RestGraph::Error in default error_handler' do
begin
RestGraph.new.get('me')
rescue ::RestGraph::Error => e
e.error .should == @error_hash
- e.message.should == @error_hash.inspect
+ e.message.should ==
+ "#{@error_hash.inspect} from https://graph.facebook.com/me"
end
end
end
describe 'with FQL API' do
@@ -58,31 +59,33 @@
# "request_args":[{"key":"method","value":"fql.query"},
# {"key":"format","value":"json"},
# {"key":"query","value":
# "SELECT name FROM bad_table WHERE uid=12345"}]}
before do
- @id = lambda{ |obj| obj }
+ @id = lambda{ |obj, url| obj }
@fql_error = '{"error_code":603,"error_msg":"Unknown table: bad"}'
@fql_error_hash = RestGraph.json_decode(@fql_error)
@bad_fql_query = 'SELECT name FROM bad_table WHERE uid="12345"'
bad_fql_request = "https://api.facebook.com/method/fql.query?" \
"format=json&query=#{CGI.escape(@bad_fql_query)}"
stub_request(:get, bad_fql_request).to_return(:body => @fql_error)
end
- it 'would call error_handler if error occurred' do
+ should 'call error_handler if error occurred' do
RestGraph.new(:error_handler => @id).fql(@bad_fql_query).
should == @fql_error_hash
end
- it 'would raise ::RestGraph::Error in default error_handler' do
+ should 'raise ::RestGraph::Error in default error_handler' do
begin
RestGraph.new.fql(@bad_fql_query)
rescue ::RestGraph::Error => e
e.error .should == @fql_error_hash
- e.message.should == @fql_error_hash.inspect
+ e.message.should.start_with?(
+ "#{@fql_error_hash.inspect} from " \
+ "https://api.facebook.com/method/fql.query?")
end
end
end
end