As far as I understand from your code, you do not rely on a session as much as you rely on an object that corresponds to the basic interface in the form of a bracket reader.
Now I don’t use RSpec, so I couldn’t say exactly how to use it in this scenario, but I would create a mock class using the parenthesis instance method or even a hash, and then check against this object, for example
fake_session = { :viewer => nil } class << fake_session include UserSession end assert_equal [], fake_session.viewer
Hope this helps.
source share