Michael Johnston
2006-Nov-30 08:01 UTC
[rspec-users] model stubs with view/controller specs: error_messages_for??
How would I set up a model stub so that <%= error_messages_for ''some_model'' %> doesn''t complain? I started going down this road: @some_model.stub! (:errors).and_return(ActiveRecord::Errors.new) but it seems like a long, hopefully uneccessary road. Cheers, Michael
David Chelimsky
2006-Nov-30 12:20 UTC
[rspec-users] model stubs with view/controller specs: error_messages_for??
On 11/30/06, Michael Johnston <lastobelus at mac.com> wrote:> How would I set up a model stub so that <%= error_messages_for > ''some_model'' %> doesn''t complain? > > I started going down this road: @some_model.stub! > (:errors).and_return(ActiveRecord::Errors.new) > > but it seems like a long, hopefully uneccessary road.Try returning a mock instead: @mock_errors = mock("errors") @some_model.stub!(:errors).and_return(@mock_errors) That''ll shorten the road quite a bit. Cheers, David> > Cheers, > Michael > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Michael Johnston
2006-Nov-30 12:57 UTC
[rspec-users] model stubs with view/controller specs: error_messages_for??
Mmm, that is how I started, but then it complains there is no "count" method On 30-Nov-06, at 4:20 AM, David Chelimsky wrote:> On 11/30/06, Michael Johnston <lastobelus at mac.com> wrote: >> How would I set up a model stub so that <%= error_messages_for >> ''some_model'' %> doesn''t complain? >> >> I started going down this road: @some_model.stub! >> (:errors).and_return(ActiveRecord::Errors.new) >> >> but it seems like a long, hopefully uneccessary road. > > Try returning a mock instead: > > @mock_errors = mock("errors") > @some_model.stub!(:errors).and_return(@mock_errors) > > That''ll shorten the road quite a bit. > > Cheers, > David >
David Chelimsky
2006-Nov-30 13:21 UTC
[rspec-users] model stubs with view/controller specs: error_messages_for??
On 11/30/06, Michael Johnston <lastobelus at mac.com> wrote:> Mmm, that is how I started, but then it complains there is no "count" > methodTwo options at this point: @mock_errors.stub!(:count).and_return(0) or @some_model.stub!(:errors).and_return([]) I think either will work. Cheers, David> > On 30-Nov-06, at 4:20 AM, David Chelimsky wrote: > > > On 11/30/06, Michael Johnston <lastobelus at mac.com> wrote: > >> How would I set up a model stub so that <%= error_messages_for > >> ''some_model'' %> doesn''t complain? > >> > >> I started going down this road: @some_model.stub! > >> (:errors).and_return(ActiveRecord::Errors.new) > >> > >> but it seems like a long, hopefully uneccessary road. > > > > Try returning a mock instead: > > > > @mock_errors = mock("errors") > > @some_model.stub!(:errors).and_return(@mock_errors) > > > > That''ll shorten the road quite a bit. > > > > Cheers, > > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >