In Rails, how do you functional test a Javascript response format?

Pass in a :format with your normal params to trigger a response in that format.

get :index, :format => 'js'

No need to mess with your request headers.

with rspec:

it "should render js" do
  xhr :get, 'index'
  response.content_type.should == Mime::JS

and in your controller action:

respond_to do |format|

Set the accepted content type to the type you want:

@request.accept = "text/javascript"

Combine this with your get :index test and it will make the appropriate call to the controller.