2014-10-16 2 views
0

내 테스트에서 rspec 및 factory_girl을 사용하고 있습니다. 문제는 json 응답을 렌더링하는 메서드를 테스트 할 때 발생합니다.rspec MissingTemplate 오류 : format => : json method

내 appointments_controller 방법 : 난 단지 "appointments.json"와 같은이 메소드를 호출하기 때문에

def index 
    @appointments = @user.admin ? @company.appointments : @user.appointments 
end 

임 여기 형식을 설정하지. 필자는 테스트에서 다음을 사용하여 지정합니다. format => : json.

describe "GET index" do 
    it "assigns all appointments as @appointments" do 
    appointment = FactoryGirl.create(:appointment) 
    get :index, { :company_id => user.company.to_param, :user_id => user.to_param }, :format => :json 
    expect(assigns(:appointments)).to eq(Appointment.all) 
    end 
end 

여기 스택에서 볼 수있는 것처럼 문제는, 그것은 여전히 ​​HTML 응답을 찾습니다 : appointments_controller_spec.rb이

Failure/Error: get :index, { :company_id => user.company.to_param, :user_id => user.to_param }, :format => :json 
ActionView::MissingTemplate: 
    Missing template appointments/index, application/index with {:locale=>[:es], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. 

답변

0

봅니다 추가

respond_with(@appointments) 

설정 후 @ 약속이

respond_to :json 

컨트롤러 시작 부분.

업데이트

어떻게 이런 식으로 지정에 대한 : @sanfor

respond_to do |format| 
    format.json { render json: @appointments.to_json } 
end 
+0

감사합니다. 이제 ActionController :: UnknownFormat 오류 – ntonnelier

+0

여전히 UnknownFormat입니다. MissingTemplete 오류를 해결 했으므로 답을 올바르게 취할 것입니다. – ntonnelier

관련 문제