This blog is part of our Rails 5 series.
Before Rails 5,
there were errors in running integration tests
when a Rack framework like Sinatra, Grape etc. were mounted within Rails
with a motive of using its session.
Problems were reported at many places including github gists and stackoverflow regarding an error which was of the following form.
NoMethodError (undefined method `each' for #<ActionDispatch::Request::Session:0x7fb8dbe7f838 not yet loaded>): rack (1.5.2) lib/rack/session/abstract/id.rb:158:in `stringify_keys'
rack (1.5.2) lib/rack/session/abstract/id.rb:95:in `update' rack (1.5.2) lib/rack/session/abstract/id.rb:258:in `prepare_session'
rack (1.5.2) lib/rack/session/abstract/id.rb:224:in `context' rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
As we can see, the error occurs due to absence of method each on an
ActionDispatch::Request::Session object.
In Rails 5, each method
was introduced to ActionDispatch::Request::Session
class making it compatible with Rack frameworks mounted in Rails and hence
avoiding the above mentioned errors in integration testing.

Written byMohit Natoo
Related blogs
- 01Rails 5 Active Record attributes APIDecember 11, 2018 · Abhay Nikam
- 02Rails 5 Create module and class level variablesSeptember 5, 2016 · Abhishek Jain
- 03Rails 5 silences assets logs in dev mode by defaultSeptember 2, 2016 · Midhun Krishna
- 04Rails 5 disables autoloading while app in productionAugust 29, 2016 · Shailesh Kalamkar