Skip to content

Instantly share code, notes, and snippets.

@yuki24
Forked from travis/gist:1084767
Created September 1, 2011 23:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yuki24/1187574 to your computer and use it in GitHub Desktop.
Save yuki24/1187574 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
@chamnap
Copy link

chamnap commented Sep 30, 2012

where is AppConfig.facebook.access_token come from?

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