Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Testing OmniAuth based login via Cucumber

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.

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!

  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!

  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)

  4. Frank says:

    I realize this is an old post, but would you mind posting a complete example for testing omniauth, showing your web steps and all?

  5. Mike Gehard says:

    Hey there Frank,

    As you mentioned, this post is pretty old and hence that code is long gone. If you wanted to take a shot at putting together some steps, I would be happy to take a look and help out.

    Mike

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *