Román González
2010-Feb-09 19:01 UTC
[rspec-users] Controller specs and Middleware on Rails
Hey guys, I''m having some problems on my controller specs regarding authentication. Previously I was using restful_authentication on the project, but after a major refactoring we changed the authentication code to "Warden": http://github.com/hassox/warden (Rack Middleware authentication). When the controller specs are executed, they fail because there is not a variable on the request''s env set by the Warden middleware. I''ve read on a previous message that I probably should use an integration test in order to tests this, I used cucumber and test everything successfully. However all my legacy rspec controller tests (that depended on a current_user) are now failing. Is there a way to patch the rSpec controller API to include this middleware on each test request? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100209/5c5e2ae5/attachment.html>
David Chelimsky
2010-Feb-09 21:54 UTC
[rspec-users] Controller specs and Middleware on Rails
2010/2/9 Rom?n Gonz?lez <romanandreg at gmail.com>:> Hey guys, > I''m having some problems on my controller specs regarding authentication. > Previously I was using restful_authentication on the project, but after a > major refactoring we changed the authentication code to > "Warden":http://github.com/hassox/warden (Rack Middleware authentication). > When the controller specs are executed, they fail because there is not a > variable on the request''s env set by the Warden middleware. I''ve read on a > previous message that I probably should use an integration test in order to > tests this, I used cucumber and test everything?successfully. However all my > legacy rspec controller tests (that depended on a current_user) are now > failing. > Is there a way to patch the rSpec controller API to include this middleware > on each test request?Controller specs don''t go through rack in rails 2, so not really. There are integration specs, which wrap the rails integration test API so you can do anything you can do in a rails integration test. Just move the files over to spec/integration, convert the requests from "get :index" to "get ''path/to/index''"and you should be pretty much good to go. Let us know how that works out. Cheers, David
Román González
2010-Feb-11 18:38 UTC
[rspec-users] Controller specs and Middleware on Rails
Hey David, Basically I didn''t try that out. Before I received your response I just re-defined all the actions related to authentication with warden, with a nahive implementation of authentication to make the specs run. Not the best solution, but it works. Thanks anyway for the help given. Regards. On Tue, Feb 9, 2010 at 1:54 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> 2010/2/9 Rom?n Gonz?lez <romanandreg at gmail.com>: > > Hey guys, > > I''m having some problems on my controller specs regarding authentication. > > Previously I was using restful_authentication on the project, but after a > > major refactoring we changed the authentication code to > > "Warden":http://github.com/hassox/warden (Rack Middleware > authentication). > > When the controller specs are executed, they fail because there is not a > > variable on the request''s env set by the Warden middleware. I''ve read on > a > > previous message that I probably should use an integration test in order > to > > tests this, I used cucumber and test everything successfully. However all > my > > legacy rspec controller tests (that depended on a current_user) are now > > failing. > > Is there a way to patch the rSpec controller API to include this > middleware > > on each test request? > > Controller specs don''t go through rack in rails 2, so not really. > > There are integration specs, which wrap the rails integration test API > so you can do anything you can do in a rails integration test. Just > move the files over to spec/integration, convert the requests from > "get :index" to "get ''path/to/index''"and you should be pretty much > good to go. > > Let us know how that works out. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100211/c8f2b695/attachment.html>