To do this, I've typically just add the HTTP_ACCEPT header. I can't  
remember where I picked this up, but it's does specify a format in  
your respond_to block:

Here's the do_request (and a sample spec) for one of my specs where  
I'm checking for a generated csv file:
def do_request
   @request.env["HTTP_ACCEPT"] = "text/csv"
   get :show, :id => "1"
end

it "should return a csv download" do
   @controller.should_receive(:send_file).with(@file, {:filename => "[EMAIL 
PROTECTED] 
}.csv", :type => 'text/csv', :disposition => 'attachment'})
   do_get
end

Now my assumption is that your mime-type would need to be registered  
in rails for this to work (if you have need of one outside of the  
norm), which arguably has the added benefit of ensuring you added it  
into your environment initializers...
--
Tim Glen



On 25-Mar-08, at 12:46 PM, Matt Berther wrote:

> Hi Seth,
>
> To get around this, are you able to test the response.headers
> collection? This tests the code that you wrote, rather than the
> template logic performed by rails.
>
> response.headers['Content-Type'].should == "text/html"
>
> Untested, of course... but it may work :)
>
> --
> Matt Berther
> http://www.mattberther.com
>
>
>
>
> On Mar 25, 2008, at 10:38 AM, Seth Ladd wrote:
>
>>> There is a guideline in TDD that you should test your code and not
>>> other people's code. The behaviour you're interested in testing is
>>> that of ActionController::Base, not of your code.
>>
>> I, of course, do not want to test Rails.  I do, however, want to
>> ensure that I have a block to handle the correct MIME type and I have
>> a template for that MIME type.  I suppose checking for the template
>> "foo/show" is good enough in this case.  If there was an error, I'd
>> get a nil there.
>>
>> I guess where this strategy falls down is if I forgot to put a
>> responds_to in my controller.  Then, no matter the format, I'll still
>> render 'foo/show' (assuming I do indeed have that template)
>>
>> Thanks for your help,
>> Seth
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to