On 7/6/07, Daniel N <[EMAIL PROTECTED]> wrote:
On 7/6/07, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On 7/5/07, Daniel N <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I'm very new to rspec so please be patient with me. > > > > I've tried to take some of my tests out of the controller specs to > check for > > things that are rendered. > > > > This has not worked so well, since my views have the controller method > > > > current_user > > > > in quite a few places. > > > > Is there any way that I can define this so that my views will be > executed? > > Will this same thing occur for all helper methods that are definied in > the > > controller? > > If I understand you correctly, you are trying to take tests for views > that were previously rails functional tests and turn them into rspec > view examples. If that is the case, you should be able to do this: > > template.stub!(:current_user).and_return(mock_model(User)) > > If not, please provide an explicit example so we can better understand > what you're talking about. > > Cheers, > David Thanx David, That looks like what I was looking for. I will try it when I get home. Cheers Daniel
Ok I've started to have a crack at this but it's getting way out of hand. Everytime I stub a method there's another one to do. I've also found that when there's a partial _detail and I've passed the :collection => @things to it it blows up complaining that the local variable is nil in dom_id( detail ) Am I doing someting wrong? The start of my specs is before do @u = mock_model( User ) @book = mock_model( Book ) public_book = mock_model( Book ) private_book = mock_model( Book ) public_book.stub!(:title=).and_return( "Public Title" ) private_book.stub!(:title=).and_return( "Private Title" ) public_book.stub!( :title ).and_return( "Public Title" ) private_book.stub!( :title ).and_return( "Private Title" ) @u.stub!( :public_books ).and_return( [public_book] ) @u.stub!( :private_books ).and_return( [private_book] ) @clip = mock_model( Clip ) @clip.stub!( :id ).and_return( 1 ) @clips = [ @clip ] template.stub!( :current_user ).and_return( @u ) end and I've only started. Is it normal to have to stub this much for a view? Cheers Daniel
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users