[Rspec-devel] Rails controller testing questions
aslak hellesoy
aslak.hellesoy at gmail.com
Fri Sep 8 11:43:32 EDT 2006
On 9/8/06, Jonathan del Strother <maillist at steelskies.com> wrote:
> 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'}
>
> and
>
> response.body.should_have_tag 'input', :attributes => {:id =>
> 'asset_name'}
>
> ?
>
> 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?
>
The controller part definitely needs more love.
Who's up for improving it? Plugin code or examples. Or even blog
entries. My wishlist:
* Show how to decouple controllers from models usgin Mocha/Stubba
* Show how to use CSS selectors to verify views (scrapi, hpricot)
* Implement rspec equivalents for Rails' assert_foo stuff that applies
to controllers.
Aslak
>
> Jon
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>
More information about the Rspec-devel
mailing list