Last Updated: September 09, 2018
· paulelliott

Speeding up cucumber

You can bypass the page loads and form filling by implementing a sign in backdoor with a little bit of code.

This assumes your sign in is governed by a SessionsController and you can sign in by passing a User instance into a sign in method. Adjust to match your authentication system.


class SessionsController
  def backdoor
    redirect_to :dashboard

MyRailsApp::Application.routes.tap do |routes|
  routes.disable_clear_and_finalize = true
  routes.draw do
    match 'backdoor', to: 'sessions#backdoor'

Now you can add a helper to your cucumber environment and use the sign_in function anywhere in your steps.


module SessionStepMethods
  def sign_in(user)
    visit "/backdoor?email=#{user.email}"

Don't worry, it is totally safe. Since the backdoor is in features/support, it gets monkey patched in when running cucumber but not in real server instances.

4 Responses
Add your response


Cool tip. I couldn't find documentation on #disable_clear_and_finalize though, what does it do?

It's also not clear from your writeup that the first snippet of code should be in 'features/support' until later on. You may want to include a file name in a comment to rectify that.

Excellent tip though. I'll definitely be using this on a project I've started.

over 1 year ago ·

#disable_clear_and_finalize basically unlocks the route set so you can add to it. Normally you can't declare a route outside of the routes.rb.

over 1 year ago ·

That's awesome! Helpful for integration tests with capybara.

over 1 year ago ·

This is powerful tool,such a great latest new version file explorer,millions users using this application,mostly used in operating system http://fileexplorerwindows.com so,hurry up and update your old file explorer version,i really like it this new features and functions.

4 months ago ·