Just set the format to specification like this ...
it "routes to #create" do expect(:post => "/post").to route_to("posts#create", :format => :json) end
Long explanation ...
The behavior you see is not specific to :format , but rather is the relationship between the characters you see in rake routes and the characters you pass to route_to .
For example, given your example above, I expect when running rake routes :
locations_nav POST /api/locations_nav(.:format) api#locations_nav
:controller and :action are not explicitly marked in the rake routes answer, since they are embedded in the MVC Rails structure, but :format displayed explicitly, and the :format pass to route_to . For example...
Similarly, you will probably see several links :id on the output of rake routes , which will be used when passing the parameter :id to route_to .
Some additional routing examples in RSpec can be seen in the rspec-rails documentation.
Inside RSpec, route_to delegates the Rails' assert_recognizes , which you can see in the Rails documentation.
DreadPirateShawn
source share