Writing functional tests for facebooker controller?

Anyone have any tips on the best methods to mock facebook requests in functional tests? Is it as simple as adding all the necessary parameters to the request? Is there any way to drown them out?

I use facebooker, which comes with a breadboard service:

  # A mock service that reads the Facebook response from fixtures
  # Adapted from http://gist.github.com/44344
  #
  #   Facebooker::MockService.fixture_path = 'path/to/dir'
  #   Facebooker::Session.current = Facebooker::MockSession.create

But when I write the basic get test, it tries to redirect the browser to the facebook page to add an application, which, I believe, indicates that the mockery does not work.

  test "loads respondent" do
    Facebooker::Session.current = Facebooker::MockSession.create
    get :index
    puts @response.body # => <html><body>You are being <a href="http://www.facebook.com/install.php?api_key=65e9d2c74b295cc5bcea935b584557f6&amp;v=1.0&amp;next=http%3A%2F%2Ftest.host%2Ffacebook">redirected</a>.</body></html>
  end
+3
source share
1 answer

I got this working with the latest facebooker version (1.0.58):

# test_helper.rb
require 'facebooker/mock/session'
require 'facebooker/mock/service'

Facebooker::MockService.fixture_path = File.join(RAILS_ROOT, 'test', 'fixtures', 'facebook')

, facebook . facebook xml , . facebook.users.getInfo facebook.users.hasAppPermission. default.xml - facebook .

 # Controller test
 test "facebook action" do  
   get :index, {:fb_sig_added => true}, :facebook_session => Facebooker::MockSession.create
   assert_response :success
 end

fb_sig_added , , facebooker . , , , .

+3

Source: https://habr.com/ru/post/1731248/


All Articles