- loading...
During integration tests you might want to load public/ files
I’ve been wondering recently “If I cache a file in public/ how do my integration tests access the file?”
By default, Rails’ integration stack only calls into the routes/controllers. So the following fails, ironically with a 404 error:
$ script/console >> app.get '404.html' => 404
It should return 200. If I cache a file into public/ I want to be able to pull it back out during the normal course of integration testing.
In integration testing, this problem manifested when I clicked a link to a cached asset, or an action redirected to a cached asset.
Ryan Tomayko seems to also have wondered about this, and had this conversation with Pratik Naik on twitter the other day that solved the problem for me:

What worked for me was to put the following at the bottom of my config/environments/cucumber.rb file (or your …/test.rb file if you do integration testing in that environment):
config.middleware.use "Rails::Rack::Static"
Now, I can successfully load assets via the get helper, or indirectly via webrat clicking links, etc:
$ script/console cucumber >> app.get '404.html' => 200
Related posts:
- Using CoffeeScript in Rails and even on Heroku I’m pretty excited about CoffeeScript as a clean-syntax replacement for...
[...] This post was Twitted by rafaelfranca [...]