Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

What's happening with the env hash in test mode?

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 log
Octocat-spinner-32 public
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 config.ru
README.md

App for this question on stack overflow.

In my Rails app, I'm accessing the env hash in one of my controller actions.

Something along the lines of:

def my_before_filter
  env['some.key'] = "Something or other"
end

This works great for my requirements.

If I start my Rails app in test environment, and visit an action like:

# /users in UsersController#index
def index
  puts env.inspect
end

Then the content of the env hash is output to the console as expected.

When I get this action from within an RSPec example, the output is an empty hash?

it 'should get the index action' do
  get :index
end
.....{}.... # rspec output

Why is the env hash empty?

Something went wrong with that request. Please try again.