我正在尝试让 Devise 的辅助方法适用于控制器规范。以下是相关代码:
# spec/spec_helper.rb
RSpec.configure do |config|
# other config stuff ...
config.include Devise::TestHelpers, :type => :controller
end
#spec/controllers/posts_controller_spec.rb
require 'spec_helper'
describe PostsController do
describe "GET index" do
admin = FactoryGirl.create(:admin)
sign_in admin # NoMethodError occurs
it "does something..." do
# etc etc etc
end
您必须经过身份验证才能从该路由呈现模板,这就是我尝试登录管理员以便测试通过的原因。谢谢你的帮助。