ApplicationController:Rails + rspec + devise = phương thức undefined `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
Kết quả:
Failure/Error: get 'index'
NoMethodError:
undefined method `authenticate_user!' for #<DashboardsController:0x007fef81f2efb8>
Ray phiên bản: 3.1.3
RSpec phiên bản: 2.8.0
lập mưu phiên bản: 1.5.3
Lưu ý: Tôi cũng tạo ra hỗ trợ/file deviser.rb nhưng điều đó không giúp đỡ. Bất kỳ ý tưởng?
[devise Wiki] (https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3- (và-rspec)) cung cấp vài cách khác nhau để tích hợp với rspec. –