Skip to content

Instantly share code, notes, and snippets.

@tmilewski
Forked from yuki24/gist:1187574
Created May 14, 2012 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmilewski/2694412 to your computer and use it in GitHub Desktop.
Save tmilewski/2694412 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