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.