Missing `secret_key_base` for 'test' environment, set this value in `config/secrets.yml`

When building the tests on CircleCI, all my tests fail with an error related to not finding the secret_key_base (see below)

I have also found this similar topic on circleCI, but the guy actually didn’t have problems with the secret_key_base, just with other environment variables.

My config/secrets.yml is not committed in my repository, and I have deployment scripts that had generated the secrets on my production infrastructure. I don’t know how this should be handled on CircleCI, I’m actually quite surprised this is not handled by default by circle (eg generating a random secret), or that nobody had the same problem.

I am using Ruby 2.3 and Rails 5. Maybe this is coming from those versions ?

The value of this variable doesn’t really matter I guess since it’s just for testing, so what should I do about it ?

*DEPRECATION WARNING: You didn’t set secret_key_base. Read the upgrade documentation to learn more about this new config option. (called from load at /home/ubuntu/MyJobGlasses/vendor/bundle/ruby/2.3.0/bin/rspec:22)

An error occurred in an after hook
NoMethodError: undefined method original_path_set' for nil:NilClass occurred at /home/ubuntu/MyJobGlasses/vendor/bundle/ruby/2.3.0/gems/rspec-rails-3.1.0/lib/rspec/rails/view_rendering.rb:96:in block (2 levels) in module:ViewRendering

You can just set it to whatever you want. For example:

Setting an environment variable doesn’t work for me. If you have checked in a config/secret.yml file that included something to read it from the environment that might (like the the default Rails configuration for production). As with the OP we don’t have any config/secrets.yml checked in.

I ended up having to just add a command in my circle.yml to make this work:

dependencies:
  pre:
    - 'echo -e "test:\n  secret_key_base: abcd1234" > config/secrets.yml'

I am also surprised that Circle doesn’t do this by default.

I chose to add the token in my test environment file. I guess it could be hardcoded, I just decided to generate a random one :

In config/environments/test.rb

# Generate a random secret token
config.secret_token = SecureRandom.hex(64)