【发布时间】:2013-06-02 03:40:28
【问题描述】:
我有一个帮助程序检查用户是否登录:
sessions_helper.rb:
module SessionsHelper
def signed_in?
!current_user.nil? # if current user is not nil then user is signed in
end
end
我想在使用 rspec 执行某些操作后测试用户是否已登录:
my_spec.rb:
require 'spec_helper'
describe "after clicking button" do
before {click_button someButton}
it "should be signed in" do
signed_in? != nil
end
end
那么我该如何让我的登录?我的规范可以访问的方法?我只需要添加:
require 'sessions_helper'?我是否最好在我的 spec_helper.rb 文件中添加一些内容,以便我的所有 spec.rb 文件都可以访问此方法?
【问题讨论】:
-
别忘了给
should打电话,否则你的测试是没用的(但是是绿色的)。
标签: ruby-on-rails rspec