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

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
db
doc
lib
log
public
script
spec
vendor
.gitignore
.rspec
Gemfile
Gemfile.lock
README.md
Rakefile
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.