Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Cucumber steps for Facebooker
# Some generic steps to work with Facebooker within Cucumber
# See full post at :
# http://griffin.oobleyboo.com/archive/facebooker-and-cucumber
#
# Standard usage like :
# Background:
# Given our default User
# And I am Facebook friends with UID 2
# And I am Facebook friends with UID 3
# And I am Facebook friends with UID 100000700000000
# And I am logged in as a Facebook user
# Simulates a request which has not come via Facebook.
# For example, an API request, or webhook request.
Given /^I am not in Facebook$/ do
@integration_session = open_session
@integration_session.canvas=false
end
# Sets up the request parameters to include details for a Facebook user,
# including their ID and their friend list (see: "Given I am Facebook friends with UID" below)
# Use as one of:
# Given I am logged in as a Facebook user
# Given I am logged in as Facebooker user 123456
Given /^I am logged in as (?:a )?Facebook user(?: (\d+))?$/ do |uid|
# Default to Facebook user ID of 1, unless it's specified
@facebook_user_id=1
@facebook_user_id=uid unless uid.blank?
# Initialize facebooker session
# This will set all the parameters that FB normally passes through, as well as set up
# a default Facebooker::Mock::Session. It all just magically happens from this one liner.
@integration_session = open_session
# Default to have friends :(
@facebook_friend_uids ||= []
# Now, we need to specify the default options for the request
@integration_session.default_request_params.merge!( :fb_sig_user => @facebook_user_id, :fb_sig_friends => @facebook_friend_uids.join(',') )
# If you need to make FB requests in your steps, you can use @integration_session to make them - they
# will then go through the fixtures defined elsewhere.
end
# Specify an ID this user is friends with. Can be used more than once.
Given /^I am Facebook friends with UID (\d+)$/ do |uid|
@facebook_friend_uids ||= []
@facebook_friend_uids << uid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment