Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
What's happening with the env hash in test mode?
Ruby JavaScript CoffeeScript
Branch: master
Failed to load latest commit information.
app First commit
config First commit
db First commit
doc First commit
lib First commit
log First commit
public
script First commit
spec First commit
vendor First commit
.gitignore First commit
.rspec First commit
Gemfile removed public/index.html
Gemfile.lock removed public/index.html
README.md updated readme
Rakefile First commit
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.