I am in the process of creating an engine that will simplify adding single signon to my app using omniauth & devise. One of the requirements is testing this with Cucumber, and it took me a little while to figure this out, so I figured I would pass it on.
Add a test app on Facebook
The first thing you need to do is set up a test app on the Facebook developers site. This will allow you to use localhost as the callback url. Otherwise, FB API will not let you authenticate, b/c the FB App configuration URL will not match your app’s URL. You will probably want 3 different FB apps. One for dev, test, and prod using localhost:3000, locahost:3001 and yourprodurl.com.
In your test FB app settings, click the “Web Site” tab and make the Site URL = localhost:3001
Save your setttings.
Add mongrel to Gemfile
I added mongrel to my test environment instead of using webrick (b/c of issues with header size of google apps callback). I would recommend doing the same. Just add it to your gemfile under the dev and test groups. Here is my Gemfile (with a bunch of other testing gems included):
Make sure you run:
Change Capybara server settings
Add these lines to “features/support/env.rb”:
You need to specify the port so mongrel is forced to start on 3001. You also need to specify the app_host as localhost, because the default “127.0.0.1″ was causing problems with FB API (url encoding I think)
Use Selenium in your scenarios
Preface your cucumber scenarios with @selenium, so you can navigate through external sites like Facebook
Of course you need to set up your cucumber step, based on how you are authenticating against facebook. I don’t provide the implementation details here. Just know that cuc is hitting the facebook URL in the first step of this scenario.
Run cucumber scenarios
You should be good to go now. Facebook will use the correct callback URL and your server will be running on the correct port to handle it.




