Im using rspec и factory_girl на моих тестах. Проблема возникает, когда я намереваюсь протестировать метод рендеринга json response.rspec MissingTemplate error on: format =>: json method
Мой метод appointments_controller:
def index
@appointments = @user.admin ? @company.appointments : @user.appointments
end
Im не установить формат здесь, потому что я только называю этот метод, как "appointments.json". Я указываю, что в моем тесте, используя: format =>: json.
appointments_controller_spec.rb:
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 ответ:
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]}.
Благодаря @sanfor. Теперь это ActionController :: UnknownFormat error – ntonnelier
Still UnknownFormat. В любом случае, я отвечу на ваш ответ, потому что он разрешил ошибку MissingTemplete – ntonnelier