无法在RSPEC中设置会话
这是我要在此处测试的文件
module Cesid
module Access
def cesid_signout
return unless session_logged
# Method to modify the cookie
set_cookie
end
def session_logged
session[:cesid_logged]
end
end
end
是我的RSPEC文件,
describe Cesid::Access do
context '#cesid_signout' do
let!(:access) { Class.new { extend Cesid::Access } }
it 'does nothing if not cesid logged' do
session[:cesid_logged] = false
expect(access.session_logged).to eql(false)
end
end
end
我在运行RSPEC后只是遇到错误。日志只是继续打印它,我无法查看错误的第一行
# /Users/renee.sarmiento/.rvm/gems/ruby-2.5.1@ls-member/gems/actionpack-4.2.8/lib/action_dispatch/testing/test_process.rb:14:in `session'
?谢谢你!
Here is the file I am trying to test
module Cesid
module Access
def cesid_signout
return unless session_logged
# Method to modify the cookie
set_cookie
end
def session_logged
session[:cesid_logged]
end
end
end
Here is my rspec file
describe Cesid::Access do
context '#cesid_signout' do
let!(:access) { Class.new { extend Cesid::Access } }
it 'does nothing if not cesid logged' do
session[:cesid_logged] = false
expect(access.session_logged).to eql(false)
end
end
end
I'm just getting an error after running the rspec. The logs just keep printing this and I can't view this first line of the error
# /Users/renee.sarmiento/.rvm/gems/ruby-2.5.1@ls-member/gems/actionpack-4.2.8/lib/action_dispatch/testing/test_process.rb:14:in `session'
Any ideas? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的用例中,我没有所有上下文。
但是很明显,您无法访问
session
在缓存的变量访问
中,因为session
不是实例变量。因此,我建议两件事:
session
实例变量如下所示通过这些修改,您的RSPEC测试应通过。
当然,这是解决问题的一种方法,但是根据您的用例,其他解决方案可能会起作用。
希望它能帮助您的理解。
对模块的工作方式有更多的了解在这里
I don't have all the context in your use case.
But it is clear that you don't have access to
session
into your cached variableaccess
sincesession
is not an instance variable.So I suggest two things:
session
instance variable into your module as explain hereWith those modification, your RSpec tests should pass.
Of course it is one way to solve your problem, but depending on your use case, other solution might work.
Hope it'll help your understanding.
More insight of how module works here just in case.