Sutto / rocket_pants

API building tools on top of ActionController. Also, an awesome name.
MIT License
981 stars 130 forks source link

Rspec doesn't honor default format JSON #92

Closed manuelmeurer closed 9 years ago

manuelmeurer commented 10 years ago

When I test my RocketPants controllers with Rspec, I have to either use get :foo, format: :json in my specs or add render formats: :json to my controllers, otherwise Rspec complains:

Failure/Error: get :foo
ActionView::MissingTemplate:
  Missing template api/v1/foos/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :slim, :haml, :rabl]}. Searched in:
    * "/Users/manuel/code/myapp/app/views"
    * "/Users/manuel/code/myapp"
    * "/"
# ./app/controllers/api/v1/foos_controller.rb:25:in `show'
# ./spec/controllers/api/v1/foos_controller_spec.rb:45:in `call'
# -e:1:in `<main>'

This is only an issue in the specs, the API works fine and returns JSON by default otherwise. Am I doing anything wrong?

Sutto commented 10 years ago

Very odd - It shouldn't even be rendering templates which is very odd - since we don't actually use rendering in rocket pants full stop.

manuelmeurer commented 10 years ago

Oh yeah, I'm using Rabl to render views, forgot to mention this. :)

This is my APIController:

class APIController < RocketPants::Base
  include ActionController::Rendering
  include ActionController::MimeResponds
  include AbstractController::Layouts

  append_view_path Rails.root.join('app', 'views')

  version 1
end

So API::V1::AccountsController#show should render app/views/api/v1/accounts/show.json.rabl, which works in development and production, but not when testing with Rspec.

I realize this might be an issue with Rspec (I don't think Rabl has anything to do with it) but I wanted to see if you or anyone else has an idea about how to fix this...

Sutto commented 9 years ago

I'm going to close this - I'm not sure on the solution, and since rendering support isn't part of RocketPants it's not something we plan on fixing. Sorry it took so long to reply to this.