[rspec-users] How to test a Rails 3 metal controller?

Thibaut Barrère thibaut.barrere at gmail.com
Tue Mar 22 08:50:57 EDT 2011


I could not find an easy solution to this question: how can I properly
test an Rails controller action?

We were trying to run the following test:

    get :show, :id => 'hello'
    response.should redirect_to("http://www.google.com")

But we got:

 undefined method `formats=' for #<LinksController:0x00000104000b40>

After reading a couple of blog posts, we tried this work-around:

class LinksController
  include ActionController::UrlFor
  include ActionController::Testing
  include Rails.application.routes.url_helpers
  include AbstractController::ViewPaths

It works only partially, we're now stuck with the limits of our monkey-
patching and get the following error:

undefined method `protected_instance_variables' for

Well - is there a clean way to test our a Rails metal with RSpec?

Thanks for your support!

-- Thibaut

More information about the rspec-users mailing list