我有这种方法来检查用户是否是管理员:
def admin?
current_user.admin == true
end
单元测试是:
require 'rails_helper'
describe StubController do
describe '.admin?' do
it "should tell if the user is admin" do
user = User.create!(email: "i@i.com", password:'123456', role: "admin", name: "Italo Fasanelli")
result = user.admin?
expect(result).to eq true
end
end
end
问题是,simplecov 告诉我这部分current_user.admin == true
没有被涵盖。
如何在此测试中测试 current_user?