Thibaut Barrère
2011-Mar-22 12:50 UTC
[rspec-users] How to test a Rails 3 metal controller?
Hi! 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 end 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 LinksController:Class Well - is there a clean way to test our a Rails metal with RSpec? Thanks for your support! -- Thibaut
David Chelimsky
2011-Mar-22 13:36 UTC
[rspec-users] How to test a Rails 3 metal controller?
On Mar 22, 2011, at 7:50 AM, Thibaut Barr?re <thibaut.barrere at gmail.com> wrote:> Hi! > > 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 > end > > 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 > LinksController:Class > > Well - is there a clean way to test our a Rails metal with RSpec?Use a request spec (in spec/requests) instead of a controller spec.> > Thanks for your support! > > -- Thibaut > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Thibaut Barrère
2011-Mar-24 09:39 UTC
[rspec-users] How to test a Rails 3 metal controller?
Hello David,> Use a request spec (in spec/requests) instead of a controller spec.Thanks, it worked perfectly! I only encountered a "stack level too deep" error, which was solved by upgrading rspec from 2.0.1 to 2.5.0, if it helps someone. Thanks again! -- Thibaut