On 7/24/07, Justin Williams <[EMAIL PROTECTED]> wrote: > I'm trying to jump on the TDD/BDD bandwagon, but am having trouble > understanding how i should mock my user. The user has a habtm > relationship to a roles model (acl_system2 plugin), but I'm not sure > how to tell rspec about a model. > > My code: > > describe UsersController do > integrate_views > > before(:each) do > @user = mock_model(User) > @user.stub!(:new_record?).and_return(false) > @user.stub!(:id).and_return(666) > @user.stub!(:email).and_return("[EMAIL PROTECTED]") > @user.stub!(:password).and_return("dummypassword") > User.stub!(:new).and_return(@user) > end > > it "should login as a tutor" do > @user.stub!(:type).and_return("Tutor") > post :login, {:login => {:email => "[EMAIL PROTECTED]", :password > => "teamup"}} > response.should redirect_to(:controller => "toolkit/overview", > :action => "index") > should_be_logged_in > end > > it "should logout" do > get :logout > response.should redirect_to(:controller => "users", :action => "login") > should_not_be_logged_in > end > > protected > > def should_be_logged_in > response.session.should_not be_nil > session[:user].should_not be_nil > end > > def should_not_be_logged_in > response.session.should_not be_nil > session[:user].should be_nil > end > end > > Unfortunately, the actual method its testing works fine, but my test > is getting the following error: > > "expected redirect to {:action=>"index", > :controller=>"toolkit/overview"}, got no redirect" > > I am pretty sure it is because I haven't set the role attribute, but > I'm not sure how to establish that relationship using stubs. I tried > setting mock_model(User, :roles => mock(Role, :title => "tutor")) but > that didn't seem to matter. > > Anyone able to shed some light on this for me?
Would you please post the code for the actions as well? > > Thanks. > > -- > - > Justin Williams > work: http://secondgearllc.com/ > play: http://carpeaqua.com > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users