Skip to content

Instantly share code, notes, and snippets.

@JanDintel
Last active December 20, 2015 05:38
Show Gist options
  • Save JanDintel/6079447 to your computer and use it in GitHub Desktop.
Save JanDintel/6079447 to your computer and use it in GitHub Desktop.
Use Factory Girl for user helper in Cucumber

Using Factory Girl with a helper for Cucumber

Using Factory Girl directly in your steps

(./features/step_definitions/function_name_steps.rb)

Given /^the user has an account$/ do
    @user = FactoryGirl.create(:user)
end

Using Factory Girl with a helper

Create helper

(./features/support/helper_name_helpers.rb)

module HelperNameHelpers
    def create_user
        @user = FactoryGirl.create(:user)
    end
end
# Tell Cucumber to include the module into each World object for each Scenario
World(HelperNameHelpers)

Refactor step

Given /^the user has an account$/ do
  create_user
end

Test should pass now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment