RSpec spec_helper 访问会话变量 [英] RSpec spec_helper access to session variable

查看:40
本文介绍了RSpec spec_helper 访问会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 RoR 和 Rspec 的新手.我正在尝试为家庭控制器编写 Rspec 测试,其中包含登录和注销等测试.我希望能够使用 spec_helper.rb 中的方法登录/注销用户

I am new to RoR and Rspec. I am trying to write Rspec tests for a home controller with tests for login and logout etc. I want to be able to login/logout a user using methods from the spec_helper.rb

但是,当我查看 spec_helper.rb 时,它说它找不到会话变量或像 post 这样的方法.这是为什么?

However when I look at the spec_helper.rb it says it cannot find the session variable or methods like post. Why is this?

如果问题有点模棱两可,请见谅.我不太确定如何解决这个问题.

Apologies if the question is a little ambiguous. I am not very sure how to frame this problem.

谢谢

推荐答案

在 RSpec 中,你可以使用:

In RSpec, you can just use:

session[:key]

不过我建议阅读 RSpec.Info: Controllers 并观看此 Railscast.

However I would suggest reading RSpec.Info: Controllers and watching this Railscast.

这篇关于RSpec spec_helper 访问会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆