Skip to content

Instantly share code, notes, and snippets.

@simonoff
Forked from travis/gist:1084767
Created March 19, 2012 08:42
Show Gist options
  • Save simonoff/2103390 to your computer and use it in GitHub Desktop.
Save simonoff/2103390 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment