Rails json API with Rspec -> ActionView::MissingTemplate

662 views Asked by At

So I have an api under

#controllers/api/v4/...rb

this api render jbuilder json under:

#views/api/v4/....json.jbuilder

I have spec:

#spec/controllers/api/v4/..._spec.rb
require 'rails_helper'

RSpec.describe Api::V4::AlbumsController do

  let(:user) { create(:user) }

  before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      sign_in(user)
  end

  describe "GET index" do
    it "returns correct types" do
      get :index, {:format => :json, :user_id => user.id}
      puts @request.body
      puts response.body
      user_response = json_response
      puts user_response
    end
  end
end

Everything is right until rendering when I get this:

Failure/Error: get :index, {:format => :json, :user_id => user.id}
  ActionView::MissingTemplate:
   Missing template api/v4/albums/index, api/api/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
     * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007ff4721d9f20>"

Does someone have an idea to solve this?

1

There are 1 answers

0
rolele On

I needed to include jbuilder in my gemfile... so it can render the .json.jbuilder views.