Skip to content

Instantly share code, notes, and snippets.

@travis
Created July 15, 2011 14:16
Show Gist options
  • Save travis/1084767 to your computer and use it in GitHub Desktop.
Save travis/1084767 to your computer and use it in GitHub Desktop.
testing facebook connect with capybara and rspec
require 'mogli'
module FacebookIntegrationHelpers
shared_context "with unconnected facebook user" do
let(:fb_user) { create_test_user(installed: false) }
after { fb_user.destroy }
end
def app_client
Mogli::AppClient.new(AppConfig.facebook.access_token, AppConfig.facebook.app_id)
end
def create_test_user(options)
query = {
:installed => true,
:permissions => 'email,offline_access'
}.merge(options)
Mogli::TestUser.create(query, app_client)
end
def complete_facebook_connect_and_wait_for(content)
within_window "Log In | Facebook" do
fill_in 'Email:', with: fb_user.email
fill_in 'Password:', with: fb_user.password
click_button "Log In"
# synchronization makes this never return, maybe because
# it's running in a different window?
without_resynchronize { click_button "Allow" }
end
wait_a_while_for { page.should have_content(content) }
end
# this is a bit of a hack - inquiring on the capybara mailing list
# for better solutions
def without_resyncronize
page.driver.options[:resynchronize] = false
yield
page.driver.options[:resynchronize] = true
end
def wait_a_while_for
default_wait = Capybara.default_wait_time
Capybara.default_wait_time = 30
yield
Capybara.default_wait_time = default_wait
end
end
RSpec.configure do |config|
config.include FacebookIntegrationHelpers, :type => :request
end
@gurgelrenan
Copy link

offline_access was deprecated, see this post:
https://developers.facebook.com/roadmap/offline-access-removal/

@vgvinay2
Copy link

vgvinay2 commented Sep 3, 2016

not working !:(

@bernardo-cs
Copy link

Here is a gist that uses rails system tests and latest capybara helpers: https://gist.github.com/golfadas/6f87deb2aa2664bbdaf8045b6c682549

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment