我正在努力让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
您必须通过身份验证才能从此路由呈现模板,这就是我尝试登录管理员以便测试通过的原因。谢谢你的帮助。
答案 0 :(得分:0)
我认为sign_in方法必须在它的上下文中或在块之前使用。尝试:
before do
admin = FactoryGirl.create(:admin)
sign_in admin # NoMethodError occurs
end