Q:

rspec MissingTemplate error on :format => :json method

Im using rspec and factory_girl on my tests.  The issue comes when i intend to test a method rendering json response. 
My appointments_controller method:
def index
  @appointments = @user.admin ?  @company.appointments : @user.appointments
end

Im not setting the format here because i only call this method like "appointments.json".  I specify that on my test using :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

The problem is, as you might see in the stack here, it still looks for an html response:
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]}.  

A:

Try to add
respond_with(@appointments)

after settings the @appointments
respond_to :json

in the beginning of controller. 
Update
How about specifying it like this:
respond_to do |format|
    format.json { render json: @appointments.to_json }
end

