1

我正在尝试让 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

您必须经过身份验证才能从该路由呈现模板,这就是我尝试登录管理员以便测试通过的原因。谢谢你的帮助。

4

1 回答 1

0

我认为 sign_in 方法必须在它的上下文中或在块之前使用。尝试:

before do
   admin = FactoryGirl.create(:admin)
   sign_in admin  # NoMethodError occurs
end
于 2012-08-03T23:00:54.773 回答