Search code examples
herokucucumberrakeasset-pipelineproduction-environment

Limit rakefile settings to specific enviorment


I have a problem, my rake file looks like this:

require File.expand_path('../config/application', __FILE__)
require 'cucumber'
require "cucumber/rake/task"

Whois::Application.load_tasks

Cucumber::Rake::Task.new(:features) do |t|
  t.cucumber_opts = "features --format pretty"
end

And the main reason of importing cucumber is to run tests with CI. But recently I've got a problem.

When I deployed to heroku and tried to run heroku run rake assets:precompile, I've got:

rake aborted!
no such file to load -- cucumber

As far as I understand, it can't find the cucumber that's only available in test env.

How can I tell rake, to use cure only in test env?


Solution

  • You'd need to wrap it in something like;

    if Rails.env.test? 
      require 'cucumber'
      require "cucumber/rake/task"
    end