Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Testing OmniAuth based login via Cucumber

Mike Gehard
Thursday, March 3, 2011

If you haven’t looked at OmniAuth for authentication with sites like Google, Github and Facebook, then you should take a look. It is pretty killer.

This morning we needed to write a Cucumber scenario to test that a user could log into the system using Google Apps.

We did a quick spike on getting OminAuth integrated, which was a super simple process, and poked around in the browser to make sure it was working OK.

Thanks to Jose Valim for providing some guidance, via the Devise test suite, on how to get this all up and running.

The basics can be found in this Gist:

I put that code in /features/support/omniauth.rb and then all I need to do is label any scenarios that need to deal with login with an @omniauth_test tag and we are all set.

As our features count grows, I could see us doing this before/after all Cucumber scenarios.

Note: You need to be using 0.2.0.beta5 of OmniAuth to get this to work. Earlier versions don’t have the testing functionality built in.

Also Note: This same functionality can be used in good, old RSpec integration tests or Steak tests as well.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

3 Comments

  1. Mark Wagner says:

    Thanks!!! this totally got me off and running in my cucumber testing of omniauth…

    I will be doing a post about it in a few days at [quicwebdevelopment.com]{http://quicwebdevelopment.com/ “QuicWebDevelopment”} about how i’m using it.

    Thanks again!

    March 22, 2011 at 8:35 pm

  2. Ben says:

    Hi Mike,

    It will be great if you can show us an example feature.

    I am new to cucumber and I don’t figure how you implement the @omniauth_test variable.

    Thank so much!

    May 21, 2011 at 1:54 am

  3. Mike Gehard says:

    @Ben -

    A sample scenario might look like:

    @omniauth_test
    Scenario: Something that requires login
    Given I am logged in
    And I go to a secure page
    Then I should see something secure

    The `Before(‘@omniauth_test)` block says only run this code before a scenario that has the @omniauth_test tag like the example above.

    Check out these two links for more info about tags and how to tag before/after blocks:
    [https://github.com/cucumber/cucumber/wiki/Tags](https://github.com/cucumber/cucumber/wiki/Tags)

    [https://github.com/cucumber/cucumber/wiki/Hooks](https://github.com/cucumber/cucumber/wiki/Hooks)

    May 22, 2011 at 10:58 am

Add New Comment Cancel reply

Your email address will not be published.

Mike Gehard

Mike Gehard
Boulder

Recent Posts

  • Using Jasmine to test CoffeeScript in a Rails 3.1 App
  • Waiting for jQuery Ajax calls to finish in Cucumber
  • Mocking Fog when using it with Carrierwave
Subscribe to Mike's Feed

Author Topics

coffeescript (1)
rails3 (10)
capybara (6)
cucumber (12)
javascript (2)
jquery (1)
webdriver (5)
carrierwave (1)
fog (1)
s3 (2)
testing (1)
rspec2 (3)
omniauth (1)
ruby (5)
devise (1)
aruba (2)
generators (2)
solr (1)
sunspot (1)
concerns (1)
mixins (1)
resque (1)
thin (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >