所以我有一个api
#controllers/api/v4/...rb
这个api渲染jbuilder json:
#views/api/v4/....json.jbuilder
我有规格:
#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
一切都是正确的,直到我得到这个:
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>"
有人有想法解决这个问题吗?
答案 0 :(得分:0)
我需要在我的gemfile中包含jbuilder ...所以它可以渲染.json.jbuilder视图。