I am testing my rails application using RSpec, and am testing the controller. Specifically, I am trying to render my jobs.json.jbuilder
view file.
My Controller
class CustomersController < ApplicationController
before_action :authenticate_member!
before_action :set_customer
def jobs
@jobs = @customer.jobs
end
My corresponding view is located in :
views/customers/jobs.json.jbuilder
My RSpec Test is:
describe "GET job" do
it "renders the jobs view" do
get 'jobs', {id: @customer.id}, {format: :json}
expect(response).to render_template("customers/jobs.json.jbuilder")
end
end
However the error I keep getting is:
Failure/Error: get :jobs, {id: @customer.id}, {format: :json}
ActionView::MissingTemplate:
Missing template customers/jobs, application/jobs with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fa219178f78>"
# ./spec/support/engine_controller.rb:25:in `process_action'
# ./spec/support/engine_controller.rb:3:in `get'
# ./spec/controllers/customers_controller_spec.rb:31:in `block (3 levels) in <top (required)>'
NOTE: If I make a jobs.html.erb
file.. then this error goes away, (and it renders the jobs.html.erb
file ) - so my question is how do i render the .json.jbuilder
view ?
Here is my spec/support/engine_controller
file:
module EngineController
def get(action, parameters = nil, session = nil, flash = nil)
process_action(action, parameters, session, flash, "GET")
end
private
def process_action(action, parameters = nil, session = nil, flash = nil, method = "GET")
parameters ||= {}
process(action, method, parameters.merge!(:use_route => :my_engine_name), session, flash, )
end