I was trying to stub something "globally", across all tests today, and had some trouble. I tried RSpec.configure do |config| config.before(:all) do MyClass.stub(:my_method) end end seems that stub is not available here yet. (I was stubbing a class method, and the class was loaded correctly). Is there somewhere else I should be putting this? At what point is the stub code loaded? (PS, the code I''m using in there works just fine in "proper" before blocks inside describe blocks) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110814/d2044dea/attachment.html>
On Sun, Aug 14, 2011 at 3:48 PM, John Hinnegan <john.hinnegan at gmail.com>wrote:> > > I was trying to stub something "globally", across all tests today, and had > some trouble. > > I tried > > RSpec.configure do |config| > config.before(:all) do > MyClass.stub(:my_method) > end > end > > seems that stub is not available here yet. (I was stubbing a class method, > and the class was loaded correctly). > > Is there somewhere else I should be putting this? At what point is the > stub code loaded? > > (PS, the code I''m using in there works just fine in "proper" before blocks > inside describe blocks) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersThat *should* work. The before''s in config are run before any before''s in your specs. And as long as you''re not using any other mocking framework, `.stub` should work as well. We''ll need some more info to help you debug. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110814/d93cb09b/attachment.html>
On Aug 14, 2011, at 10:15 PM, Justin Ko wrote:> On Sun, Aug 14, 2011 at 3:48 PM, John Hinnegan <john.hinnegan at gmail.com> wrote: > > > I was trying to stub something "globally", across all tests today, and had some trouble. > > I tried > > RSpec.configure do |config| > config.before(:all) do > MyClass.stub(:my_method) > end > end > > seems that stub is not available here yet. (I was stubbing a class method, and the class was loaded correctly). > > Is there somewhere else I should be putting this? At what point is the stub code loaded? > > (PS, the code I''m using in there works just fine in "proper" before blocks inside describe blocks) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > That *should* work. The before''s in config are run before any before''s in your specs. And as long as you''re not using any other mocking framework, `.stub` should work as well. We''ll need some more info to help you debug.The problem is not that it''s a global config, but it''s in before(:all). Put it in a before(:each) and it will work. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110814/87675b97/attachment.html>
the error I got was that .stub was not defined on the class from that block I can try to repro it outside of my current project later if you need actual failing code, but that''s a representative snippet of what I tried On Sun, Aug 14, 2011 at 8:15 PM, Justin Ko <jko170 at gmail.com> wrote:> > > On Sun, Aug 14, 2011 at 3:48 PM, John Hinnegan <john.hinnegan at gmail.com>wrote: > >> >> >> I was trying to stub something "globally", across all tests today, and had >> some trouble. >> >> I tried >> >> RSpec.configure do |config| >> config.before(:all) do >> MyClass.stub(:my_method) >> end >> end >> >> seems that stub is not available here yet. (I was stubbing a class >> method, and the class was loaded correctly). >> >> Is there somewhere else I should be putting this? At what point is the >> stub code loaded? >> >> (PS, the code I''m using in there works just fine in "proper" before blocks >> inside describe blocks) >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > That *should* work. The before''s in config are run before any before''s in > your specs. And as long as you''re not using any other mocking framework, > `.stub` should work as well. We''ll need some more info to help you debug. > > > _______________________________________________ > 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/20110814/6ef7bdc0/attachment.html>
Thanks, cheers On Sun, Aug 14, 2011 at 8:17 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Aug 14, 2011, at 10:15 PM, Justin Ko wrote: > > On Sun, Aug 14, 2011 at 3:48 PM, John Hinnegan <john.hinnegan at gmail.com>wrote: > >> >> >> I was trying to stub something "globally", across all tests today, and had >> some trouble. >> >> I tried >> >> RSpec.configure do |config| >> config.before(:all) do >> MyClass.stub(:my_method) >> end >> end >> >> seems that stub is not available here yet. (I was stubbing a class >> method, and the class was loaded correctly). >> >> Is there somewhere else I should be putting this? At what point is the >> stub code loaded? >> >> (PS, the code I''m using in there works just fine in "proper" before blocks >> inside describe blocks) >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > That *should* work. The before''s in config are run before any before''s in > your specs. And as long as you''re not using any other mocking framework, > `.stub` should work as well. We''ll need some more info to help you debug. > > > The problem is not that it''s a global config, but it''s in before(:all). Put > it in a before(:each) and it will work. > > 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/20110814/168042b6/attachment-0001.html>
On Aug 14, 2011, at 10:31 PM, John Hinnegan wrote:> > On Sun, Aug 14, 2011 at 8:15 PM, Justin Ko <jko170 at gmail.com> wrote: > > > On Sun, Aug 14, 2011 at 3:48 PM, John Hinnegan <john.hinnegan at gmail.com> wrote: > > > I was trying to stub something "globally", across all tests today, and had some trouble. > > I tried > > RSpec.configure do |config| > config.before(:all) do > MyClass.stub(:my_method) > end > end > > seems that stub is not available here yet. (I was stubbing a class method, and the class was loaded correctly). > > Is there somewhere else I should be putting this? At what point is the stub code loaded? > > (PS, the code I''m using in there works just fine in "proper" before blocks inside describe blocks) > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > That *should* work. The before''s in config are run before any before''s in your specs. And as long as you''re not using any other mocking framework, `.stub` should work as well. We''ll need some more info to help you debug. > the error I got was that .stub was not defined on the class from that block> > I can try to repro it outside of my current project later if you need actual failing code, but that''s a representative snippet of what I triedDid you try using before(:each)? David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110815/2c1fa2dc/attachment.html>