David Ladowitz David Ladowitz - 2 months ago 5x
Ruby Question

How to require fixture_builder in cucumber?

I have a Rails 4.1 project that uses RSpec and Cucumber.
I've recently added fixture_builder.

fixture_builder.rb includes logic to rebuild fixtures any time the file changes.
This works fine for RSpec with

require 'fixture_builder'
in spec_helper.rb.

However, when running Cucumber tests fixture_builder.rb is not called, so fixtures are not updated if any changes have been made to fixture_builder.rb.

Is there an equivalent config file like spec_helper.rb for Cucumber?


By default, Cucumber loads all *.rb files in the same directory as the feature(s) it's running and all subdirectories of that directory, so you can put your require in any file you want in any of those directories.

The conventional thing to do is to put 'support' code like require in features/support/env.rb, or in another file in features/support if your env.rb gets too big.

The cucumber-rails gem provides a generator that sets up Cucumber to work with Rails. If you haven't already, install the gem and run

rails g cucumber:install

to create features/support/env.rb and the rest of the usual Rails + Cucumber setup.