public
Last active

testing facebook connect with capybara and rspec

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.