프로젝트의 관리 섹션에 대한 기본 컨트롤러를 만들고 있습니다. 관리 섹션에서 모든 컨트롤러가 상속받습니다.Rspec + Devise + BaseController
#app/controllers/admins/base_controller.rb
class Admins::BaseController < ApplicationController
layout "admin_cms"
before_filter :authenticate_admin!
end
-
#spec/controllers/admins/base_controller_spec.rb
require 'spec_helper'
describe Admins::BaseController do
controller do
def index
end
end
describe "before_filter#authenticate_admin!" do
before(:each) do
@admin = FactoryGirl.create(:admin)
@request.env["devise.mapping"] = Devise.mappings[:admin]
end
context "when admin is not logged in" do
it "redirect admin to sign_in path" do
get :index
response.should redirect_to new_admin_session_path
end
end
end
end
나는 이미 내 spec_helper.rb에 고안 :: TestHelpers을 inclueded 한이 사양 실행할 때이 오류 받고 있어요 : 나는 변경
Admins::BaseController
before_filter#authenticate_admin!
when admin is not logged in
redirect admin to sign_in path (FAILED - 1)
Failures:
1) Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path
Failure/Error: get :index
ActionView::MissingTemplate:
Missing template anonymous/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0xbaf75d4>"
# ./spec/controllers/admins/base_controller_spec.rb:17:in `block (4 levels) in <top (required)>'
Finished in 0.17124 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/admins/base_controller_spec.rb:16 # Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path
을 내 사양 :
require 'spec_helper'
describe Admins::BaseController do
controller do
def index
render nothing: true
end
end
describe "before_filter#authenticate_admin!" do
context "when admin is not logged in" do
it "redirect admin to sign_in path" do
get :index
response.should redirect_to new_admin_session_path
end
end
end
end
Failures:
1) Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path
Failure/Error: response.should redirect_to new_admin_session_path
Expected response to be a <:redirect>, but was <200>
그래서, 어떤 이유가 authenticate_admin에 입력 아니에요 :는 지금은이 오류를 받고 있어요! 필터 전에. 나는 일종의 잃어버린. 다시 한번 감사드립니다.
저는 Rails 3.2.13, Ruby 2.0.0, Rspec-rails 2.13.0 및 Devise 2.2.3을 사용하고 있습니다. 누군가가 나를 도울 수 있다면 나는 정말로 appreacite. 미리 감사드립니다.