이전 필터로 사용할 응용 프로그램 컨트롤러에서 메서드를 테스트하려고합니다. 이렇게하려면 제대로 작동하는지 확인하기 위해 적용된 이전 필터를 사용하여 테스트에서 익명 컨트롤러를 설치해야합니다.익명 컨트롤러에 대한 Rspec 스텁보기
describe ApplicationController do
controller do
before_filter :authenticated
def index
end
end
describe "user authenticated" do
let(:session_id){"session_id"}
let(:user){OpenStruct.new(:email => "[email protected]", :name => "Colin Gemmell")}
before do
request.cookies[:session_id] = session_id
UserSession.stub!(:find).with(session_id).and_return(user)
get :index
end
it { should assign_to(:user){user} }
end
end
을 그리고 응용 프로그램 컨트롤러는 다음과 같이이다 :
는시험은 현재 다음과 같습니다
class ApplicationController < ActionController::Base
protect_from_forgery
def authenticated
@user = nil
end
end
내가 테스트를 실행 지금까지 나는 다음과 같은 오류
를 받고있을 때 내 문제입니다1) ApplicationController user authenticated
Failure/Error: get :index
ActionView::MissingTemplate:
Missing template stub_resources/index with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html], :locale=>[:en, :en]} in view paths "#<RSpec::Rails::ViewRendering::PathSetDelegatorResolver:0x984f310>"
문서에 따르면보기는 rendered when running controller tests이 아니지만 아니오를 나타냅니다. 뷰가 존재하지 않기 때문에 이해할 수있는이 작업에 대한 스텁이 있음
누구나이 문제를 해결하거나 뷰를 스텁링하는 방법을 알 수 있습니다.
건배 콜린 G
치료를 받았다. – pythonandchips