ApplicationController中:Rails + rspec + devise =未定義的方法`authenticate_user!'
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
protect_from_forgery
end
DashboardsController:
class DashboardsController < ApplicationController
def index
end
end
DashboardsControllerSpec:
require 'spec_helper'
describe DashboardsController do
include Devise::TestHelpers
describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end
end
結果:
Failure/Error: get 'index'
NoMethodError:
undefined method `authenticate_user!' for #<DashboardsController:0x007fef81f2efb8>
Rails的版本:3.1.3
Rspec的版本:2.8.0
設計版本:1.5.3
注:我還創建支持/ deviser.rb文件,但沒有幫助。有任何想法嗎?
的[設計維基](https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(和-rspec的))提供了一種幾種不同的方式來整合設計與rspec。 – 2012-01-11 12:40:45