Lille
2010-Sep-03 17:12 UTC
[rspec-users] how to invoke multiple controllers in the same describe block?
Hi, I seek to authenticate and then test other routing in RSpec, but the standard RSpec vernacular... describe SomeController do it "blah-blah" do get :new ... end end ...doesn''t seem to allow me to post my login data, as in the following pseudo-code: describe SomeController do before(:each) do post :controller=>"authentication", :action=> "create", :new_session=>{"user_name"=>"Lille"...} end ... end I''ve scanned all the methods in the RDoc, but I cannot identify the manner in which I may specify the controller directly. Any help? Thanks, Lille
David Chelimsky
2010-Sep-03 17:53 UTC
[rspec-users] how to invoke multiple controllers in the same describe block?
On Sep 3, 2010, at 12:12 PM, Lille wrote:> Hi, > > I seek to authenticate and then test other routing in RSpec, but the > standard RSpec vernacular... > > describe SomeController do > > it "blah-blah" do > get :new > ... > end > > end > > ...doesn''t seem to allow me to post my login data, as in the following > pseudo-code: > > describe SomeController do > > before(:each) do > post :controller=>"authentication", :action=> > "create", :new_session=>{"user_name"=>"Lille"...} > end > ... > end > > I''ve scanned all the methods in the RDoc, but I cannot identify the > manner in which I may specify the controller directly. Any help?Controller specs wrap behaviour of ActionController::TestCase, which is designed to handle one request per example. You could do this in request specs (integration specs in rspec-2), which derive behaviour from rails integration tests. HTH, David
Pat Maddox
2010-Sep-03 21:22 UTC
[rspec-users] how to invoke multiple controllers in the same describe block?
Lille wrote:> Hi, > > I seek to authenticate and then test other routing in RSpec, but the > standard RSpec vernacular... > > describe SomeController do > > it "blah-blah" do > get :new > ... > end > > end > > ...doesn''t seem to allow me to post my login data, as in the following > pseudo-code: > > describe SomeController do > > before(:each) do > post :controller=>"authentication", :action=> > "create", :new_session=>{"user_name"=>"Lille"...} > end > ... > end > > I''ve scanned all the methods in the RDoc, but I cannot identify the > manner in which I may specify the controller directly. Any help? > > Thanks, > > Lille > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >You can''t do that with basic controller specs. What you _can_ do is stub a method on the controller (maybe #current_user) or set a bit of session info like session[:user_id]. So you can set up the spec so that a user is logged in when making the request, but you can''t make multiple requests in a single spec. For that you''ll want the integration specs or Cucumber. Pat