Rails Minitest 테스트 오류
조회수 1397회
레일즈에서 미니테스트로 테스트를 짜고 돌리는데 아래와 같은 오류가 나왔습니다.
Minitest::UnexpectedError: AbstractController::DoubleRenderError: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
위의 에러는 어떻게 해결하고 테스트해야하나요?
제가 테스트 하고 싶었던것은 아래와 같은 단순한 conteroller test였습니다.
class UsersControllerTest < ActionController::TestCase
test '자기소개를 가져올 수 있다.' do
get :info, format: :js
assert_response :success
end
end
실제 컨트롤러
class UsersController < ApplicationController
def info
end
end
테스트가 아닌 실제 뷰에서는
link_to('정보', info_user_url, remote: true)
위와같은 식으로 링크를 넣어줘서 링크를 클릭하면 info.js.coffee 뷰 잘 보여지고 있습니다. 테스트에서만 에러가 나네요.
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
http://guides.rubyonrails.org/layouts_and_rendering.html#avoiding-double-render-errors 를 참고해보세요.
뷰가 두번이상 렌더링 됐을 때 에러가 발생하는 것 같은데...,
테스트에서만 에러 나는 것이라면, 다음 링크를 참조해보세요. http://stackoverflow.com/questions/4291755/rspec-test-of-custom-devise-session-controller-fails-with-abstractcontrollerac
Devise::TestHelpers를 사용해서 해결은 됐다고 합니다.
require 'test_helper' class UsersControllerTest < ActionController::TestCase include Devise::TestHelpers test '자기소개를 가져올 수 있다.' do setup_controller_for_warden # 이것과 request.env["devise.mapping"] = Devise.mappings[:user] # 이부분 추가 get :info, format: :js assert_response :success end end
- 답변감사합니다. 그런데 뷰는 하나만 정의한 상태입니다.(info.coffee) 테스트에서 format: :js를 붙히면 위의 에러가 나고 format: :js 를 지우면 테스트가 통과하네요..왜그런걸까요?ㅠ 알 수 없는 사용자 2016.3.25 17:19
댓글 입력