黄瓜is_admin?测试

时间:2011-11-28 05:59:20

标签: rspec

我不知道在哪里放这篇文章,但这个主题更相似 我的问题。

我有一个登录系统,就像这样:

  

的ApplicationController:   包括SessionsHelper

私有

helper_method:current_user

def current_user  @current_user || = User.find(session [:user_id])if session [:user_id] 端

  

SessionsHelper:     def is_admin?      @current_user&& @ current_user.id == 1     端

     

特征/支持/ env.rb:   世界(SessionsHelper)

所以,如果我测试

  

is_admin?.should be_true

它返回:

预计nil为真(RSpec :: Expectations :: ExpectationNotMetError)       ./features/step_definitions/users/add_user.rb:23:in /^I should signin$/' features/users/add_user.feature:13:in我应该签字'

但我登录了!为什么?从中测试身份验证系统的方法是什么? 划痕?

1 个答案:

答案 0 :(得分:1)

  

我不知道在哪里放这篇文章,但这个主题更相似   我的问题。   黄瓜邮件列表是:   http://groups.google.com/group/cukes

但我可以告诉你,你的问题是一个范围问题。你的is_admin? 方法 这是添加到黄瓜的世界无法访问你的 应用 controller的@current_user变量。