我有一个帮助器,其中包含检查用户是否已登录的方法:
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
那么如何制作我的signed_in?我的规格可以访问的方法?我只需要添加:
require 'sessions_helper'
?我最好在spec_helper.rb文件中添加一些内容,以便我的所有spec.rb文件都可以访问此方法吗?
答案 0 :(得分:1)
require 'spec_helper'
describe SessionsHelper
describe "after clicking button" do
before {click_button someButton}
it "should be signed in" do
helper.signed_in? != nil
end
end
end
您可以在对象“helper”上调用辅助方法