From jamesmead44 at gmail.com Sun Apr 6 13:02:12 2008 From: jamesmead44 at gmail.com (James Mead) Date: Sun, 6 Apr 2008 18:02:12 +0100 Subject: [mocha-developer] Rails patch Message-ID: <1db558f00804061002q48dad15fnd709f06be346073a@mail.gmail.com> I've just submitted a Rails ticket [1] which I've been meaning to submit for ages. The associated patch makes ActiveRecord "respond_to?" dynamic finder methods. The idea is that some new functionality I've added to Mocha will (optionally) allow you to get warnings or errors if you attempt to stub a non-existent method. With the current Rails implementation, this leads to false negatives when you stub dynamic finder methods. If you're using Mocha with Rails and are interested in using this Mocha functionality, please add a "+1" in the comments on the ticket. I suppose it would be nice to retro-fit the patch to older versions of Rails, but I'll leave that for another day. -- James. http://blog.floehopper.org http://tumble.floehopper.org [1] http://dev.rubyonrails.org/ticket/11538 From jamesmead44 at gmail.com Sun Apr 6 18:35:36 2008 From: jamesmead44 at gmail.com (James Mead) Date: Sun, 6 Apr 2008 23:35:36 +0100 Subject: [mocha-developer] Rails patch In-Reply-To: <1db558f00804061002q48dad15fnd709f06be346073a@mail.gmail.com> References: <1db558f00804061002q48dad15fnd709f06be346073a@mail.gmail.com> Message-ID: <1db558f00804061535p1690d988hfce47d01272f6a2a@mail.gmail.com> On 06/04/2008, James Mead wrote: > > I've just submitted a Rails ticket [1] which I've been meaning to submit > for ages. The associated patch makes ActiveRecord "respond_to?" dynamic > finder methods. > > The idea is that some new functionality I've added to Mocha will > (optionally) allow you to get warnings or errors if you attempt to stub a > non-existent method. > > With the current Rails implementation, this leads to false negatives when > you stub dynamic finder methods. > > If you're using Mocha with Rails and are interested in using this Mocha > functionality, please add a "+1" in the comments on the ticket. > > I suppose it would be nice to retro-fit the patch to older versions of > Rails, but I'll leave that for another day. Looks like it has already been committed [1]. Thanks. -- James. http://blog.floehopper.org http://tumble.floehopper.org [1] http://dev.rubyonrails.org/changeset/9235 From jamesmead44 at gmail.com Tue Apr 8 04:41:11 2008 From: jamesmead44 at gmail.com (James Mead) Date: Tue, 8 Apr 2008 09:41:11 +0100 Subject: [mocha-developer] Fwd: Content filtered message notification In-Reply-To: References: Message-ID: <1db558f00804080141s5691e53ej57ed7e41822b6576@mail.gmail.com> Forwarding this to the list, because Mailman's content filtering didn't like your digital signature attachment... ---------- Forwarded message ---------- From: Ken Collins To: mocha-developer at rubyforge.org Date: Mon, 7 Apr 2008 20:06:20 -0400 Subject: Re: [mocha-developer] Rails patch Very nice patch too! The method/test additions were wonderful. - Ken On Apr 6, 2008, at 6:35 PM, James Mead wrote: On 06/04/2008, James Mead wrote: > > > > > I've just submitted a Rails ticket [1] which I've been meaning to submit > > for ages. The associated patch makes ActiveRecord "respond_to?" dynamic > > finder methods. > > > > The idea is that some new functionality I've added to Mocha will > > (optionally) allow you to get warnings or errors if you attempt to stub > > a > > non-existent method. > > > > With the current Rails implementation, this leads to false negatives > > when > > you stub dynamic finder methods. > > > > If you're using Mocha with Rails and are interested in using this Mocha > > functionality, please add a "+1" in the comments on the ticket. > > > > I suppose it would be nice to retro-fit the patch to older versions of > > Rails, but I'll leave that for another day. > > > > > Looks like it has already been committed [1]. Thanks. > -- > James. > http://blog.floehopper.org > http://tumble.floehopper.org > > [1] http://dev.rubyonrails.org/changeset/9235 > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- James. http://blog.floehopper.org http://tumble.floehopper.org From kengruven at gmail.com Thu Apr 24 19:15:09 2008 From: kengruven at gmail.com (Ken Harris) Date: Thu, 24 Apr 2008 16:15:09 -0700 Subject: [mocha-developer] Mocking class methods: documentation suggestion Message-ID: Hi Mocha people, I'm just starting to use Mocha, and I had some trouble, so I thought I'd share my experiences so other people don't have to go through what I did. New mocks worked just fine (a=mock(); a.expects(:b), ...) -- very cool. But I wanted to mess with class methods, like Time.now, and it was not happy with that for some reason: $ irb >> require 'mocha' => true >> Time.stubs(:now).returns("pancakes") NoMethodError: undefined method `stub' for nil:NilClass from /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.6/lib/mocha/object.rb:57:in `stubs' from (irb):3 I found remarkably similar examples online (e.g., ) which don't work here, either, which puzzled me. I ran mocha's tests and they all passed. So I dug through the source code, and discovered that some setup methods need to get run before class methods will work, and they get run automatically as part of unit tests, but not otherwise. I would suggest some combination of (a) adding to the docs that mocks only work as advertised inside a TestCase, (b) in object.rb:57, when $stubba is nil, say something like "you need to run setup_mocha first!", and/or (c) say in the docs what the setup method is, and how to run it (maybe it's there, but I didn't see it). But in any event, this message will soon be in google, so maybe that's enough. cheers, - Ken From jamesmead44 at gmail.com Fri Apr 25 04:43:24 2008 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 25 Apr 2008 09:43:24 +0100 Subject: [mocha-developer] Mocking class methods: documentation suggestion In-Reply-To: References: Message-ID: <1db558f00804250143v545541a0y534768c2c4e46d88@mail.gmail.com> Hi Ken, Thanks for taking the trouble to post to the mailing list (I'm sorry that your message got held up in the moderation queue because you didn't subscribe - I keep thinking I should move the mailing list over to google-groups). This is something that someone else reported a while ago [1], so it is clearly a problem. I do remember changing some of the docs to try and improve things, but obviously not in the right place. Can you suggest anywhere specific that you would have noticed it? I like the idea of a better error message when setup hasn't been run. I'll look into that. It was intentional that the setup method wasn't in the docs, because I thought that only test framework authors would need to know about it - I thought it might confuse other people. But perhaps if it was documented sensibly this need not be the case. Thanks. -- James. http://blog.floehopper.org http://tumble.floehopper.org [1] http://rubyforge.org/pipermail/mocha-developer/2007-July/000406.html 2008/4/25 Ken Harris : > Hi Mocha people, > > I'm just starting to use Mocha, and I had some trouble, so I thought > I'd share my experiences so other people don't have to go through what > I did. > > New mocks worked just fine (a=mock(); a.expects(:b), ...) -- very > cool. But I wanted to mess with class methods, like Time.now, and it > was not happy with that for some reason: > > $ irb > >> require 'mocha' > => true > >> Time.stubs(:now).returns("pancakes") > NoMethodError: undefined method `stub' for nil:NilClass > from > /opt/local/lib/ruby/gems/1.8/gems/mocha-0.5.6/lib/mocha/object.rb:57:in > `stubs' > from (irb):3 > > I found remarkably similar examples online (e.g., > ) > which don't work here, either, which puzzled me. I ran mocha's tests > and they all passed. > > So I dug through the source code, and discovered that some setup > methods need to get run before class methods will work, and they get > run automatically as part of unit tests, but not otherwise. > > I would suggest some combination of (a) adding to the docs that mocks > only work as advertised inside a TestCase, (b) in object.rb:57, when > $stubba is nil, say something like "you need to run setup_mocha > first!", and/or (c) say in the docs what the setup method is, and how > to run it (maybe it's there, but I didn't see it). > > But in any event, this message will soon be in google, so maybe that's > enough. > From kengruven at gmail.com Fri Apr 25 17:15:39 2008 From: kengruven at gmail.com (Ken Harris) Date: Fri, 25 Apr 2008 14:15:39 -0700 Subject: [mocha-developer] Mocking class methods: documentation suggestion Message-ID: Hi James, A nice user-friendly error message would cover 99% of it. Truth be told, people (including me, I'm not ashamed to say) often don't even look at the docs until something goes wrong, and if it went wrong by saying "RuntimeError: you need to call mocha::setup_some_stuff if you want to use mocks outside of a TestCase! --love, mocha.rb" then the docs wouldn't really have mattered. Perhaps since the docs are largely by-example, we could just add another example, "Using Mocha outside of TestCase". It would be about 5 lines long. :-) - Ken From jamesmead44 at gmail.com Sat Apr 26 10:24:36 2008 From: jamesmead44 at gmail.com (James Mead) Date: Sat, 26 Apr 2008 15:24:36 +0100 Subject: [mocha-developer] Mocking class methods: documentation suggestion In-Reply-To: References: Message-ID: <1db558f00804260724u44398172ub03f896b5ae9cdb0@mail.gmail.com> Cool. I've added a feature request [1] so it doesn't get forgotten. -- James. http://blog.floehopper.org http://tumble.floehopper.org [1] http://rubyforge.org/tracker/index.php?func=detail&aid=19786&group_id=1917&atid=7480 2008/4/25 Ken Harris : > Hi James, > > A nice user-friendly error message would cover 99% of it. Truth be > told, people (including me, I'm not ashamed to say) often don't even > look at the docs until something goes wrong, and if it went wrong by > saying > > "RuntimeError: you need to call mocha::setup_some_stuff if you > want to use mocks outside of a TestCase! --love, mocha.rb" > > then the docs wouldn't really have mattered. > > Perhaps since the docs are largely by-example, we could just add > another example, "Using Mocha outside of TestCase". It would be about > 5 lines long. :-) > > > - Ken > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >