Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get tests passing live and stubbed

  • Loading branch information...
commit e90bdab6b8a94ad8b54d6fb6d8305be18239f825 1 parent 5dfbf13
@arsduo authored
View
10 spec/cases/graph_api_batch_spec.rb
@@ -508,7 +508,7 @@
batch_api.get_picture('me')
end
puts pictures.inspect
- pictures.first.should == "http://google.com" # the value in the yml
+ pictures.first.should =~ /http\:\/\// # works both live & stubbed
end
it "handles requests for two different tokens" do
@@ -557,8 +557,12 @@
let(:friends_callback) { lambda {|data| friends_result } }
it 'calls the callback with the appropriate data' do
- me_callback.should_receive(:call).with('id'=>'123')
- friends_callback.should_receive(:call).with(['id'=>'456'])
+ me_callback.should_receive(:call).with(hash_including(
+ 'id' => KoalaTest.user1
+ ))
+ friends_callback.should_receive(:call).with([
+ hash_including('id' => KoalaTest.user2)
+ ])
@api.batch do |batch_api|
batch_api.get_object('me', &me_callback)
batch_api.get_connections('me', 'friends', &friends_callback)
View
51 spec/cases/graph_api_spec.rb
@@ -15,35 +15,27 @@
# Most API methods have the same signature, we test get_object representatively
# and the other methods which do some post-processing locally
context '#get_object' do
- it 'is called' do
- @api.get_object('koppel', &post_processing)
- end
-
it 'returns result of block' do
+ result = {"id" => 1, "name" => 1, "updated_time" => 1}
+ @api.stub(:api).and_return(result)
post_processing.should_receive(:call).
- with("id" => 1, "name" => 1, "updated_time" => 1).
- and_return('new result')
+ with(result).and_return('new result')
@api.get_object('koppel', &post_processing).should == 'new result'
end
end
context '#get_picture' do
- it 'is called with picture url' do
- post_processing.should_receive(:call)
- @api.get_picture('lukeshepard', &post_processing)
- end
-
it 'returns result of block' do
+ result = "http://facebook.com/"
+ @api.stub(:api).and_return("Location" => result)
post_processing.should_receive(:call).
- with('http://facebook.com/').
- and_return('new result')
+ with(result).and_return('new result')
@api.get_picture('lukeshepard', &post_processing).should == 'new result'
end
end
context '#fql_multiquery' do
before do
- MultiJson.stub(:dump)
@api.should_receive(:get_object).and_return([
{"name" => "query1", "fql_result_set" => [{"id" => 123}]},
{"name" => "query2", "fql_result_set" => ["id" => 456]}
@@ -51,29 +43,26 @@
end
it 'is called with resolved response' do
- resolved_result = { 'query1'=>[{'id'=>123}],'query2'=>[{'id'=>456}] }
- post_processing.should_receive(:call).with(resolved_result)
- @api.fql_multiquery(&post_processing)
- end
-
- it 'returns result of block' do
- post_processing.should_receive(:call).and_return('id'=>'123', 'id'=>'456')
- @api.fql_multiquery(&post_processing).should == {'id'=>'123', 'id'=>'456'}
+ resolved_result = {
+ 'query1' => [{'id' => 123}],
+ 'query2' => [{'id'=>456}]
+ }
+ post_processing.should_receive(:call).
+ with(resolved_result).and_return('id'=>'123', 'id'=>'456')
+ @api.fql_multiquery({}, &post_processing).should ==
+ {'id'=>'123', 'id'=>'456'}
end
end
context '#get_page_access_token' do
- it 'is called with just access token' do
- post_processing.should_receive(:call).with(Koala::MockHTTPService::APP_ACCESS_TOKEN)
- @api.get_page_access_token '/my_page', &post_processing
- end
-
it 'returns result of block' do
- post_processing.should_receive(:call).and_return('base64-encoded access token')
- @api.get_page_access_token('/my_page', &post_processing).should == 'base64-encoded access token'
+ token = Koala::MockHTTPService::APP_ACCESS_TOKEN
+ @api.stub(:api).and_return("access_token" => token)
+ post_processing.should_receive(:call).
+ with(token).and_return('base64-encoded access token')
+ @api.get_page_access_token('facebook', &post_processing).should ==
+ 'base64-encoded access token'
end
end
-
end
-
end
View
2  spec/fixtures/mock_facebook_responses.yml
@@ -82,7 +82,7 @@ graph_api:
with_token: '[{"code": 200, "headers":[{"name":"Location","value":"http://google.com"}]}]'
batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "me/friends"}]) %>:
post:
- with_token: '[{"code": 200, "body":"{\"id\":\"123\"}"}, {"code": 200, "body":"{\"data\":[{\"id\":\"456\"}],\"paging\":{}}"}]'
+ with_token: '[{"code": 200, "body":"{\"id\":\"koppel\"}"}, {"code": 200, "body":"{\"data\":[{\"id\":\"lukeshepard\"}],\"paging\":{}}"}]'
batch=<%= MultiJson.dump([{"method"=>"get", "relative_url"=>"me"}, {"method"=>"get", "relative_url"=>"#{OAUTH_DATA["app_id"]}/insights?access_token=#{CGI.escape APP_ACCESS_TOKEN}"}]) %>:
post:
with_token: '[{"code": 200, "body":"{\"id\":\"123\"}"}, {"code": 200, "body":"{\"data\":[],\"paging\":{}}"}]'
View
12 spec/spec_helper.rb
@@ -5,16 +5,16 @@
end
# In Ruby 1.9.2 versions before patchlevel 290, the default Psych
-# parser has an issue with YAML merge keys, which
+# parser has an issue with YAML merge keys, which
# fixtures/mock_facebook_responses.yml relies heavily on.
-#
+#
# Anyone using an earlier version will see missing mock response
# errors when running the test suite similar to this:
-#
+#
# RuntimeError:
# Missing a mock response for graph_api: /me/videos: source=[FILE]: post: with_token
# API PATH: /me/videos?source=[FILE]&format=json&access_token=*
-#
+#
# For now, it seems the best fix is to just downgrade to the old syck YAML parser
# for these troubled versions.
#
@@ -29,8 +29,8 @@
# ensure consistent to_json behavior
# this must be required first so mock_http_service loads the YAML as expected
-require 'support/ordered_hash'
-require 'support/json_testing_fix'
+require 'support/ordered_hash'
+require 'support/json_testing_fix'
# set up our testing environment
require 'support/mock_http_service'
Please sign in to comment.
Something went wrong with that request. Please try again.