I received this error while writing controller tests for an API. ActionController::UnknownFormat was introduced with Rails 4 and has not been well documented yet.

Here’s how I resolved the issue.

Doesn’t Work

controller_spec.rb
1
2
3
  ...
  post :create, title: "Example Title", body: "Example body"
  ...

Works

controller_spec.rb
1
2
3
  ...
  post :create, post: { title: "Example Title", body: "Example body" }
  ...

You may still face an ActiveModel::ForbiddenAttributesError but that’s a different issue requiring that you address strong_params.

Comments