[Rspec-devel] Rails controller testing questions

Jonathan del Strother maillist at steelskies.com
Fri Sep 8 11:23:24 EDT 2006

I'm fine with model specs, but for some reason I'm struggling a bit  
making controller specs feel right.  I'd love to see some more  
examples if anyone has any they're willing to share.

Also, I have a few questions...


Is there any difference between

     should_have_tag 'input', :attributes => {:id => 'asset_name'}


     response.body.should_have_tag 'input', :attributes => {:id =>  


Both styles are used on http://rspec.rubyforge.org/tools/rails.html


Is it possible to get route recognition testing to work in rspec?  eg -
assert_recognizes({:controller => 'assets', :action => 'new'},
                       {:path => "/assets/new", :method => :get})


How about named urls?  Being able to use
get assets_url
would be fairly handy


Finally, is it just me, or is rspec controller testing missing a  
bunch of useful functionality?  For example, in rails functional  
tests there's
assert_redirect_to :action => 'index'
and I'm struggling to find an equivalent in rspec.  The closest thing  
I can find is
     response.redirect_url.should_be 'http://test.host/assets'
which is liable to break if, say, your default controller in  
routes.rb is AssetsController.

I really want to like rspec for controller testing, but I keep on  
running into little annoyances like the above.  Am I the only one?


More information about the Rspec-devel mailing list