From cohen.jeff at gmail.com Fri Jun 1 22:18:44 2007 From: cohen.jeff at gmail.com (Jeff Cohen) Date: Fri, 1 Jun 2007 21:18:44 -0500 Subject: [mocha-developer] Preview of Latest Mocha Changes In-Reply-To: <1db558f00704121021n3af7264bxd170bce7cbaae485@mail.gmail.com> References: <1db558f00704121021n3af7264bxd170bce7cbaae485@mail.gmail.com> Message-ID: <3d7e01550706011918g65c0ffa1x2f8a2394713108aa@mail.gmail.com> On 4/12/07, James Mead wrote: > > I've finally managed to find some time to do some serious work on > Mocha. There are some code snippets on my blog > ( > http://blog.floehopper.org/articles/2007/04/12/preview-of-latest-mocha-changes > ) > showing the new functionality available in trunk (revision 128). I > don't don't know how many people out there are using trunk, but it > would be great to get some feedback on these changes before I make a > new release. > [snip] Any news on that new release? Jeff From jamesmead44 at gmail.com Mon Jun 4 04:35:56 2007 From: jamesmead44 at gmail.com (James Mead) Date: Mon, 4 Jun 2007 09:35:56 +0100 Subject: [mocha-developer] Preview of Latest Mocha Changes In-Reply-To: <3d7e01550706011918g65c0ffa1x2f8a2394713108aa@mail.gmail.com> References: <1db558f00704121021n3af7264bxd170bce7cbaae485@mail.gmail.com> <3d7e01550706011918g65c0ffa1x2f8a2394713108aa@mail.gmail.com> Message-ID: <1db558f00706040135h1222f23cpea4b6e90468eeea4@mail.gmail.com> On 02/06/07, Jeff Cohen wrote: > Any news on that new release? I had hoped to do some more work before release, but it doesn't look like I'm going to get round to it for a bit - I'll try and get a release out tomorrow evening. Thanks for your interest. -- James. http://blog.floehopper.org From cohen.jeff at gmail.com Mon Jun 4 09:37:46 2007 From: cohen.jeff at gmail.com (Jeff Cohen) Date: Mon, 4 Jun 2007 08:37:46 -0500 Subject: [mocha-developer] Preview of Latest Mocha Changes In-Reply-To: <1db558f00706040135h1222f23cpea4b6e90468eeea4@mail.gmail.com> References: <1db558f00704121021n3af7264bxd170bce7cbaae485@mail.gmail.com> <3d7e01550706011918g65c0ffa1x2f8a2394713108aa@mail.gmail.com> <1db558f00706040135h1222f23cpea4b6e90468eeea4@mail.gmail.com> Message-ID: <3d7e01550706040637t32c5c358k33bdd3e6efb21123@mail.gmail.com> Don't rush on account of me :-) Really, I was just curious, and I'm more than happy to use the trunk code for now. I'm just getting started with Mocha, so it's not like I'm waiting on any particular feature. Thanks again. Jeff On 6/4/07, James Mead wrote: > > On 02/06/07, Jeff Cohen wrote: > > Any news on that new release? > > I had hoped to do some more work before release, but it doesn't look > like I'm going to get round to it for a bit - I'll try and get a > release out tomorrow evening. > > Thanks for your interest. > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > From jamesmead44 at gmail.com Fri Jun 8 17:09:48 2007 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 8 Jun 2007 22:09:48 +0100 Subject: [mocha-developer] Preview of Latest Mocha Changes In-Reply-To: <3d7e01550706040637t32c5c358k33bdd3e6efb21123@mail.gmail.com> References: <1db558f00704121021n3af7264bxd170bce7cbaae485@mail.gmail.com> <3d7e01550706011918g65c0ffa1x2f8a2394713108aa@mail.gmail.com> <1db558f00706040135h1222f23cpea4b6e90468eeea4@mail.gmail.com> <3d7e01550706040637t32c5c358k33bdd3e6efb21123@mail.gmail.com> Message-ID: <1db558f00706081409u58829a8hf011937c3789ee3f@mail.gmail.com> Mocha 0.5.0 now released. -- James. http://blog.floehopper.org From jamesmead44 at gmail.com Fri Jun 8 17:11:36 2007 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 8 Jun 2007 22:11:36 +0100 Subject: [mocha-developer] Mocha 0.5 released Message-ID: <1db558f00706081411p5633b8e5t7fcfff4747fe5698@mail.gmail.com> * Hamcrest-style parameter matchers * Values returned and exceptions raised on consecutive invocations * Yields on consecutive invocations * Multiple yields on single invocation * Invocation dispatch fixed * Deprecated returning result of a Proc -- James. http://blog.floehopper.org From kevin.clark at gmail.com Fri Jun 8 17:14:49 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Fri, 8 Jun 2007 14:14:49 -0700 Subject: [mocha-developer] Mocha 0.5 released In-Reply-To: <1db558f00706081411p5633b8e5t7fcfff4747fe5698@mail.gmail.com> References: <1db558f00706081411p5633b8e5t7fcfff4747fe5698@mail.gmail.com> Message-ID: You're awesome. On 6/8/07, James Mead wrote: > * Hamcrest-style parameter matchers > * Values returned and exceptions raised on consecutive invocations > * Yields on consecutive invocations > * Multiple yields on single invocation > * Invocation dispatch fixed > * Deprecated returning result of a Proc > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From kevin.clark at gmail.com Mon Jun 11 18:19:02 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Mon, 11 Jun 2007 15:19:02 -0700 Subject: [mocha-developer] Mocking system/` Message-ID: This drives me insane on a regular basis. How does one mock system('blah') or `blah` ? Adding expectations on Kernel doesn't do it. Adding expectations on Object just makes me sad: Object.any_instance.expects(:system).with('ls') # => #.system('ls') - expected calls: 0, actual calls: 1 And this really shouldn't work (and doesn't): Object.expects(:system).with('ls') # => #.system('ls') - expected calls: 1, actual calls: 0 Anyone have a trick they like? -- Kevin Clark http://glu.ttono.us From fred at 82ask.com Mon Jun 11 18:26:01 2007 From: fred at 82ask.com (Frederick Cheung) Date: Mon, 11 Jun 2007 23:26:01 +0100 Subject: [mocha-developer] Mocking system/` In-Reply-To: References: Message-ID: <353EDE06-3E60-46E8-B6E4-ABCCC061B02C@82ask.com> On 11 Jun 2007, at 23:19, Kevin Clark wrote: > This drives me insane on a regular basis. How does one mock > system('blah') or `blah` ? > > Adding expectations on Kernel doesn't do it. Adding expectations on > Object just makes me sad: > > Object.any_instance.expects(:system).with('ls') > # => #.system('ls') - expected calls: 0, actual > calls: 1 > > And this really shouldn't work (and doesn't): > > Object.expects(:system).with('ls') > # => #.system('ls') - expected calls: 1, actual > calls: 0 > > Anyone have a trick they like? system etc... are in a module that is included most places, so if we have class Foo def my_method_calling_system system('echo "hello world"') end end Then you need to do something like f = Foo.new f.expects(:system). f.my_method_calling_system I would have expected Object.any_instance.expects(:system) to work but a cursory attempt suggests it doesn;t Fred From kevin.clark at gmail.com Tue Jun 12 00:53:59 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Mon, 11 Jun 2007 21:53:59 -0700 Subject: [mocha-developer] Mocking system/` In-Reply-To: <353EDE06-3E60-46E8-B6E4-ABCCC061B02C@82ask.com> References: <353EDE06-3E60-46E8-B6E4-ABCCC061B02C@82ask.com> Message-ID: Bah, turned out to be a Merb reloading bug. Nevermind. On 6/11/07, Frederick Cheung wrote: > > On 11 Jun 2007, at 23:19, Kevin Clark wrote: > > > This drives me insane on a regular basis. How does one mock > > system('blah') or `blah` ? > > > > Adding expectations on Kernel doesn't do it. Adding expectations on > > Object just makes me sad: > > > > Object.any_instance.expects(:system).with('ls') > > # => #.system('ls') - expected calls: 0, actual > > calls: 1 > > > > And this really shouldn't work (and doesn't): > > > > Object.expects(:system).with('ls') > > # => #.system('ls') - expected calls: 1, actual > > calls: 0 > > > > Anyone have a trick they like? > > system etc... are in a module that is included most places, so if we > have > > class Foo > def my_method_calling_system > system('echo "hello world"') > end > end > > Then you need to do something like > > f = Foo.new > f.expects(:system). > f.my_method_calling_system > > > I would have expected Object.any_instance.expects(:system) to work > but a cursory attempt suggests it doesn;t > > Fred > > > > > > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From jpywtora at calpoly.edu Tue Jun 12 01:18:04 2007 From: jpywtora at calpoly.edu (jpywtora at calpoly.edu) Date: Tue, 12 Jun 2007 05:18:04 +0000 (GMT) Subject: [mocha-developer] Mocking system/` Message-ID: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> Great; However, I was hoping to see how to mock the backtics, any ideas? Object.any_instance.expects(:`).with("ls") # my guess, but is wrong Thanks --- Original Message --- > Bah, turned out to be a Merb reloading bug. Nevermind. > > On 6/11/07, Frederick Cheung wrote: > > > > On 11 Jun 2007, at 23:19, Kevin Clark wrote: > > > > > This drives me insane on a regular basis. How does one mock > > > system('blah') or `blah` ? > > > > > > Adding expectations on Kernel doesn't do it. Adding expectations on > > > Object just makes me sad: > > > > > > Object.any_instance.expects(:system).with('ls') > > > # => #.system('ls') - expected calls: 0, actual > > > calls: 1 > > > > > > And this really shouldn't work (and doesn't): > > > > > > Object.expects(:system).with('ls') > > > # => #.system('ls') - expected calls: 1, actual > > > calls: 0 > > > > > > Anyone have a trick they like? > > > > system etc... are in a module that is included most places, so if we > > have > > > > class Foo > > def my_method_calling_system > > system('echo "hello world"') > > end > > end > > > > Then you need to do something like > > > > f = Foo.new > > f.expects(:system). > > f.my_method_calling_system > > > > > > I would have expected Object.any_instance.expects(:system) to work > > but a cursory attempt suggests it doesn;t > > > > Fred > > > > > > > > > > > > _______________________________________________ > > mocha-developer mailing list > > mocha-developer at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mocha-developer > > > > > -- > Kevin Clark > http://glu.ttono.us > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From pbattley at gmail.com Tue Jun 12 05:33:19 2007 From: pbattley at gmail.com (Paul Battley) Date: Tue, 12 Jun 2007 10:33:19 +0100 Subject: [mocha-developer] Mocking system/` In-Reply-To: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> Message-ID: <2ab6a5020706120233q188c0eeaq83fe3b782007136@mail.gmail.com> On 12/06/07, jpywtora at calpoly.edu wrote: > Great; However, I was hoping to see how to mock the backtics, any ideas? > > Object.any_instance.expects(:`).with("ls") # my guess, but is wrong I don't think it's possible. `` (or %x) isn't a normal message - it's a language construct of its own. (Sorry for the vague, hand-waving explanation!) A more verbose but more flexible alternative might be to use popen or open3 in your code instead of backticks. You *can* mock that. Paul. From kevin.clark at gmail.com Tue Jun 12 11:08:00 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Tue, 12 Jun 2007 08:08:00 -0700 Subject: [mocha-developer] Mocking system/` In-Reply-To: <2ab6a5020706120233q188c0eeaq83fe3b782007136@mail.gmail.com> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <2ab6a5020706120233q188c0eeaq83fe3b782007136@mail.gmail.com> Message-ID: Well, in the parse tree both %x and `` become an xstr, but I _thought_ those became a method dispatch. Maybe it happens in the C and so can't be intercepted. On 6/12/07, Paul Battley wrote: > On 12/06/07, jpywtora at calpoly.edu wrote: > > Great; However, I was hoping to see how to mock the backtics, any ideas? > > > > Object.any_instance.expects(:`).with("ls") # my guess, but is wrong > > I don't think it's possible. `` (or %x) isn't a normal message - it's > a language construct of its own. (Sorry for the vague, hand-waving > explanation!) > > A more verbose but more flexible alternative might be to use popen or > open3 in your code instead of backticks. You *can* mock that. > > Paul. > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From jpywtora at calpoly.edu Tue Jun 12 13:00:57 2007 From: jpywtora at calpoly.edu (John Pywtorak) Date: Tue, 12 Jun 2007 10:00:57 -0700 Subject: [mocha-developer] Mocking system/` In-Reply-To: References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <2ab6a5020706120233q188c0eeaq83fe3b782007136@mail.gmail.com> Message-ID: <466ED149.3090409@calpoly.edu> irb(main):005:0> module Kernel irb(main):006:1> def `(*args) irb(main):007:2> raise "nope, not gonna do it" irb(main):008:2> end irb(main):009:1> end => nil irb(main):010:0> `ls` RuntimeError: nope, not gonna do it from (irb):7:in ``' from (irb):10 irb(main):011:0> That gives me hope, any ideas? Kevin Clark wrote: > Well, in the parse tree both %x and `` become an xstr, but I _thought_ > those became a method dispatch. Maybe it happens in the C and so can't > be intercepted. > > On 6/12/07, Paul Battley wrote: >> On 12/06/07, jpywtora at calpoly.edu wrote: >>> Great; However, I was hoping to see how to mock the backtics, any ideas? >>> >>> Object.any_instance.expects(:`).with("ls") # my guess, but is wrong >> I don't think it's possible. `` (or %x) isn't a normal message - it's >> a language construct of its own. (Sorry for the vague, hand-waving >> explanation!) >> >> A more verbose but more flexible alternative might be to use popen or >> open3 in your code instead of backticks. You *can* mock that. >> >> Paul. >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer >> > > From daikini at gmail.com Tue Jun 12 13:06:13 2007 From: daikini at gmail.com (Jonathan Younger) Date: Tue, 12 Jun 2007 11:06:13 -0600 Subject: [mocha-developer] Mocking system/` In-Reply-To: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> Message-ID: <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> On Jun 11, 2007, at 11:18 PM, jpywtora at calpoly.edu wrote: > Great; However, I was hoping to see how to mock the backtics, any > ideas? > > Object.any_instance.expects(:`).with("ls") # my guess, but is wrong > Try adding double quotes around the backtick like this: .expects(:"`").with("ls") -Jonathan > --- Original Message --- >> Bah, turned out to be a Merb reloading bug. Nevermind. >> >> On 6/11/07, Frederick Cheung wrote: >>> >>> On 11 Jun 2007, at 23:19, Kevin Clark wrote: >>> >>>> This drives me insane on a regular basis. How does one mock >>>> system('blah') or `blah` ? >>>> >>>> Adding expectations on Kernel doesn't do it. Adding expectations on >>>> Object just makes me sad: >>>> >>>> Object.any_instance.expects(:system).with('ls') >>>> # => #.system('ls') - expected calls: 0, actual >>>> calls: 1 >>>> >>>> And this really shouldn't work (and doesn't): >>>> >>>> Object.expects(:system).with('ls') >>>> # => #.system('ls') - expected calls: 1, actual >>>> calls: 0 >>>> >>>> Anyone have a trick they like? >>> >>> system etc... are in a module that is included most places, so if we >>> have >>> >>> class Foo >>> def my_method_calling_system >>> system('echo "hello world"') >>> end >>> end >>> >>> Then you need to do something like >>> >>> f = Foo.new >>> f.expects(:system). >>> f.my_method_calling_system >>> >>> >>> I would have expected Object.any_instance.expects(:system) to work >>> but a cursory attempt suggests it doesn;t >>> >>> Fred >>> >>> >>> >>> >>> >>> _______________________________________________ >>> mocha-developer mailing list >>> mocha-developer at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mocha-developer >>> >> >> >> -- >> Kevin Clark >> http://glu.ttono.us >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer > > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From justin at spiceworks.com Tue Jun 12 14:05:56 2007 From: justin at spiceworks.com (Justin Perkins) Date: Tue, 12 Jun 2007 13:05:56 -0500 Subject: [mocha-developer] advice on new failures with 0.5.0 Message-ID: Hi all, We just updated to the latest version of Mocha and now we're seeing a lot of odd test failures. If this isn't the appropriate place for a question like this, please let me know. Say I have code like this in a controller: DataMonitor.toggle_notification! And I mock it like this: DataMonitor.any_instance.stubs(:toggle_notification!) This would work fine with Mocha 0.4.0, but with 0.5.0 it looks like Mocha is differentiating between a method call with parenthesis to one without parenthesis. I don't really understand how this could happen, nor the logic in why parenthesis should be required for an empty parameter list, so if somebody could explain it to me that'd be awesome. For reference, this is the failure we're now seeing: #.toggle_notification!() - expected calls: 0, actual calls: 1 Similar expectations: toggle_notification! The release notes at the API site (http://mocha.rubyforge.org/files/ RELEASE.html) have not been updated, so I wasn't able to determine the reason behind this change on my own. Thanks for Mocha, I love it, but for now am sticking with the 0.4.0 release. -justin From jamesmead44 at gmail.com Tue Jun 12 14:32:25 2007 From: jamesmead44 at gmail.com (James Mead) Date: Tue, 12 Jun 2007 19:32:25 +0100 Subject: [mocha-developer] advice on new failures with 0.5.0 In-Reply-To: References: Message-ID: <1db558f00706121132g545261a1l4676eb4561e6663f@mail.gmail.com> Hi Justin, I just tried to reproduce your error... require 'test/unit' require 'rubygems' require 'mocha' class MyTest < Test::Unit::TestCase class DataMonitor def toggle_notification! end end def test_me DataMonitor.any_instance.stubs(:toggle_notification!) DataMonitor.new.toggle_notification! end end This seems to work fine for me. Can you try to distil one of your failing tests down to make it as simple and self-contained as you can, but still exhibiting the error? We need to reproduce the bug before we can fix it. Also can you tell us how you are including Mocha in your project? e.g. Rails plugin, Ruby gem, etc. Sorry about the missing release notes - I'll try and get that sorted asap - in the meantime this blog post pretty much covers it - http://blog.floehopper.org/articles/2007/06/08/mocha-0-5-released. -- James. http://blog.floehopper.org From kevin.clark at gmail.com Tue Jun 12 14:58:57 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Tue, 12 Jun 2007 11:58:57 -0700 Subject: [mocha-developer] Mocking system/` In-Reply-To: <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> Message-ID: I could have sworn I tried that. Is it working for you? > Try adding double quotes around the backtick like this: > > .expects(:"`").with("ls") > > -Jonathan > > > > --- Original Message --- > >> Bah, turned out to be a Merb reloading bug. Nevermind. > >> > >> On 6/11/07, Frederick Cheung wrote: > >>> > >>> On 11 Jun 2007, at 23:19, Kevin Clark wrote: > >>> > >>>> This drives me insane on a regular basis. How does one mock > >>>> system('blah') or `blah` ? > >>>> > >>>> Adding expectations on Kernel doesn't do it. Adding expectations on > >>>> Object just makes me sad: > >>>> > >>>> Object.any_instance.expects(:system).with('ls') > >>>> # => #.system('ls') - expected calls: 0, actual > >>>> calls: 1 > >>>> > >>>> And this really shouldn't work (and doesn't): > >>>> > >>>> Object.expects(:system).with('ls') > >>>> # => #.system('ls') - expected calls: 1, actual > >>>> calls: 0 > >>>> > >>>> Anyone have a trick they like? > >>> > >>> system etc... are in a module that is included most places, so if we > >>> have > >>> > >>> class Foo > >>> def my_method_calling_system > >>> system('echo "hello world"') > >>> end > >>> end > >>> > >>> Then you need to do something like > >>> > >>> f = Foo.new > >>> f.expects(:system). > >>> f.my_method_calling_system > >>> > >>> > >>> I would have expected Object.any_instance.expects(:system) to work > >>> but a cursory attempt suggests it doesn;t > >>> > >>> Fred > >>> > >>> > >>> > >>> > >>> > >>> _______________________________________________ > >>> mocha-developer mailing list > >>> mocha-developer at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/mocha-developer > >>> > >> > >> > >> -- > >> Kevin Clark > >> http://glu.ttono.us > >> _______________________________________________ > >> mocha-developer mailing list > >> mocha-developer at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/mocha-developer > > > > _______________________________________________ > > mocha-developer mailing list > > mocha-developer at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mocha-developer > > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From daikini at gmail.com Tue Jun 12 15:19:55 2007 From: daikini at gmail.com (Jonathan Younger) Date: Tue, 12 Jun 2007 13:19:55 -0600 Subject: [mocha-developer] Mocking system/` In-Reply-To: References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> Message-ID: <3D2AFC5E-B680-4B29-9F91-E9298C645CF4@gmail.com> On Jun 12, 2007, at 12:58 PM, Kevin Clark wrote: > I could have sworn I tried that. Is it working for you? > Yup, it's working fine for me. # foo_test.rb require 'rubygems' require 'test/unit' require 'mocha' class Foo def files `ls` end end class FooTest < Test::Unit::TestCase def test_should_return_files foo = Foo.new foo.expects(:"`").with("ls").returns("list of files") assert_equal "list of files", foo.files end end megiddo:~/Projects jonathan$ ruby foo_test.rb Loaded suite foo_test Started . Finished in 0.000801 seconds. 1 tests, 2 assertions, 0 failures, 0 errors megiddo:~/Projects jonathan$ ruby foo_test.rb Loaded suite foo_test Started . Finished in 0.000764 seconds. 1 tests, 2 assertions, 0 failures, 0 errors megiddo:~/Projects jonathan$ -Jonathan >> Try adding double quotes around the backtick like this: >> >> .expects(:"`").with("ls") >> >> -Jonathan >> >> >>> --- Original Message --- >>>> Bah, turned out to be a Merb reloading bug. Nevermind. >>>> >>>> On 6/11/07, Frederick Cheung wrote: >>>>> >>>>> On 11 Jun 2007, at 23:19, Kevin Clark wrote: >>>>> >>>>>> This drives me insane on a regular basis. How does one mock >>>>>> system('blah') or `blah` ? >>>>>> >>>>>> Adding expectations on Kernel doesn't do it. Adding >>>>>> expectations on >>>>>> Object just makes me sad: >>>>>> >>>>>> Object.any_instance.expects(:system).with('ls') >>>>>> # => #.system('ls') - expected calls: 0, actual >>>>>> calls: 1 >>>>>> >>>>>> And this really shouldn't work (and doesn't): >>>>>> >>>>>> Object.expects(:system).with('ls') >>>>>> # => #.system('ls') - expected calls: 1, actual >>>>>> calls: 0 >>>>>> >>>>>> Anyone have a trick they like? >>>>> >>>>> system etc... are in a module that is included most places, so >>>>> if we >>>>> have >>>>> >>>>> class Foo >>>>> def my_method_calling_system >>>>> system('echo "hello world"') >>>>> end >>>>> end >>>>> >>>>> Then you need to do something like >>>>> >>>>> f = Foo.new >>>>> f.expects(:system). >>>>> f.my_method_calling_system >>>>> >>>>> >>>>> I would have expected Object.any_instance.expects(:system) to work >>>>> but a cursory attempt suggests it doesn;t >>>>> >>>>> Fred >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> mocha-developer mailing list >>>>> mocha-developer at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/mocha-developer >>>>> >>>> >>>> >>>> -- >>>> Kevin Clark >>>> http://glu.ttono.us >>>> _______________________________________________ >>>> mocha-developer mailing list >>>> mocha-developer at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/mocha-developer >>> >>> _______________________________________________ >>> mocha-developer mailing list >>> mocha-developer at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mocha-developer >> >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer >> > > > -- > Kevin Clark > http://glu.ttono.us > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From daikini at gmail.com Tue Jun 12 15:28:24 2007 From: daikini at gmail.com (Jonathan Younger) Date: Tue, 12 Jun 2007 13:28:24 -0600 Subject: [mocha-developer] Mocking system/` In-Reply-To: References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> Message-ID: <1E3AE9B7-15CF-4933-9EE7-F8D452B4924D@gmail.com> On Jun 12, 2007, at 12:58 PM, Kevin Clark wrote: > I could have sworn I tried that. Is it working for you? > Actually after further testing the double quotes aren't required after all. It seems the key to getting it to work is to put the expectation on the object calling the ` method rather than on Object.any_instance. -Jonathan >> Try adding double quotes around the backtick like this: >> >> .expects(:"`").with("ls") >> >> -Jonathan >> >> >>> --- Original Message --- >>>> Bah, turned out to be a Merb reloading bug. Nevermind. >>>> >>>> On 6/11/07, Frederick Cheung wrote: >>>>> >>>>> On 11 Jun 2007, at 23:19, Kevin Clark wrote: >>>>> >>>>>> This drives me insane on a regular basis. How does one mock >>>>>> system('blah') or `blah` ? >>>>>> >>>>>> Adding expectations on Kernel doesn't do it. Adding >>>>>> expectations on >>>>>> Object just makes me sad: >>>>>> >>>>>> Object.any_instance.expects(:system).with('ls') >>>>>> # => #.system('ls') - expected calls: 0, actual >>>>>> calls: 1 >>>>>> >>>>>> And this really shouldn't work (and doesn't): >>>>>> >>>>>> Object.expects(:system).with('ls') >>>>>> # => #.system('ls') - expected calls: 1, actual >>>>>> calls: 0 >>>>>> >>>>>> Anyone have a trick they like? >>>>> >>>>> system etc... are in a module that is included most places, so >>>>> if we >>>>> have >>>>> >>>>> class Foo >>>>> def my_method_calling_system >>>>> system('echo "hello world"') >>>>> end >>>>> end >>>>> >>>>> Then you need to do something like >>>>> >>>>> f = Foo.new >>>>> f.expects(:system). >>>>> f.my_method_calling_system >>>>> >>>>> >>>>> I would have expected Object.any_instance.expects(:system) to work >>>>> but a cursory attempt suggests it doesn;t >>>>> >>>>> Fred >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> mocha-developer mailing list >>>>> mocha-developer at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/mocha-developer >>>>> >>>> >>>> >>>> -- >>>> Kevin Clark >>>> http://glu.ttono.us >>>> _______________________________________________ >>>> mocha-developer mailing list >>>> mocha-developer at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/mocha-developer >>> >>> _______________________________________________ >>> mocha-developer mailing list >>> mocha-developer at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mocha-developer >> >> _______________________________________________ >> mocha-developer mailing list >> mocha-developer at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mocha-developer >> > > > -- > Kevin Clark > http://glu.ttono.us > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From kevin.clark at gmail.com Tue Jun 12 15:44:03 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Tue, 12 Jun 2007 12:44:03 -0700 Subject: [mocha-developer] Mocking system/` In-Reply-To: <1E3AE9B7-15CF-4933-9EE7-F8D452B4924D@gmail.com> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> <1E3AE9B7-15CF-4933-9EE7-F8D452B4924D@gmail.com> Message-ID: Ah, must have been my reloading issue that was keeping it from working. Cool, thanks for the help guys. On 6/12/07, Jonathan Younger wrote: > > On Jun 12, 2007, at 12:58 PM, Kevin Clark wrote: > > > I could have sworn I tried that. Is it working for you? > > > > Actually after further testing the double quotes aren't required > after all. It seems the key to getting it to work is to put the > expectation on the object calling the ` method rather than on > Object.any_instance. > > -Jonathan > > >> Try adding double quotes around the backtick like this: > >> > >> .expects(:"`").with("ls") > >> > >> -Jonathan > >> > >> > >>> --- Original Message --- > >>>> Bah, turned out to be a Merb reloading bug. Nevermind. > >>>> > >>>> On 6/11/07, Frederick Cheung wrote: > >>>>> > >>>>> On 11 Jun 2007, at 23:19, Kevin Clark wrote: > >>>>> > >>>>>> This drives me insane on a regular basis. How does one mock > >>>>>> system('blah') or `blah` ? > >>>>>> > >>>>>> Adding expectations on Kernel doesn't do it. Adding > >>>>>> expectations on > >>>>>> Object just makes me sad: > >>>>>> > >>>>>> Object.any_instance.expects(:system).with('ls') > >>>>>> # => #.system('ls') - expected calls: 0, actual > >>>>>> calls: 1 > >>>>>> > >>>>>> And this really shouldn't work (and doesn't): > >>>>>> > >>>>>> Object.expects(:system).with('ls') > >>>>>> # => #.system('ls') - expected calls: 1, actual > >>>>>> calls: 0 > >>>>>> > >>>>>> Anyone have a trick they like? > >>>>> > >>>>> system etc... are in a module that is included most places, so > >>>>> if we > >>>>> have > >>>>> > >>>>> class Foo > >>>>> def my_method_calling_system > >>>>> system('echo "hello world"') > >>>>> end > >>>>> end > >>>>> > >>>>> Then you need to do something like > >>>>> > >>>>> f = Foo.new > >>>>> f.expects(:system). > >>>>> f.my_method_calling_system > >>>>> > >>>>> > >>>>> I would have expected Object.any_instance.expects(:system) to work > >>>>> but a cursory attempt suggests it doesn;t > >>>>> > >>>>> Fred > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> _______________________________________________ > >>>>> mocha-developer mailing list > >>>>> mocha-developer at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/mocha-developer > >>>>> > >>>> > >>>> > >>>> -- > >>>> Kevin Clark > >>>> http://glu.ttono.us > >>>> _______________________________________________ > >>>> mocha-developer mailing list > >>>> mocha-developer at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/mocha-developer > >>> > >>> _______________________________________________ > >>> mocha-developer mailing list > >>> mocha-developer at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/mocha-developer > >> > >> _______________________________________________ > >> mocha-developer mailing list > >> mocha-developer at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/mocha-developer > >> > > > > > > -- > > Kevin Clark > > http://glu.ttono.us > > _______________________________________________ > > mocha-developer mailing list > > mocha-developer at rubyforge.org > > http://rubyforge.org/mailman/listinfo/mocha-developer > > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From justin at spiceworks.com Tue Jun 12 16:02:55 2007 From: justin at spiceworks.com (Justin Perkins) Date: Tue, 12 Jun 2007 15:02:55 -0500 Subject: [mocha-developer] advice on new failures with 0.5.0 In-Reply-To: <1db558f00706121132g545261a1l4676eb4561e6663f@mail.gmail.com> References: <1db558f00706121132g545261a1l4676eb4561e6663f@mail.gmail.com> Message-ID: <047B0091-6E32-4248-ABEF-CBB4A5FD952D@spiceworks.com> > Can you try to distil one of your failing tests down to make it as > simple > and self-contained as you can, but still exhibiting the error? We > need to > reproduce the bug before we can fix it. In trying to make a small, reproducible test case (that passed every time) I discovered an error (surprise) in our code that wasn't discovered by the previous version of Mocha. This new exception led me to wrongly accuse Mocha. All is well and we are happily using 0.5.0 now. > Also can you tell us how you are including Mocha in your project? > e.g. Rails > plugin, Ruby gem, etc. It's a Rails project, using the Mocha gem. > Sorry about the missing release notes - I'll try and get that > sorted asap - > in the meantime this blog post pretty much covers it - > http://blog.floehopper.org/articles/2007/06/08/mocha-0-5-released. Thanks for that, hadn't seen that yet. -justin On Jun 12, 2007, at 1:32 PM, James Mead wrote: > Hi Justin, > > I just tried to reproduce your error... > > require 'test/unit' > require 'rubygems' > require 'mocha' > > class MyTest < Test::Unit::TestCase > > class DataMonitor > def toggle_notification! > end > end > > def test_me > DataMonitor.any_instance.stubs(:toggle_notification!) > DataMonitor.new.toggle_notification! > end > > end > > This seems to work fine for me. > > Can you try to distil one of your failing tests down to make it as > simple > and self-contained as you can, but still exhibiting the error? We > need to > reproduce the bug before we can fix it. > > Also can you tell us how you are including Mocha in your project? > e.g. Rails > plugin, Ruby gem, etc. > > Sorry about the missing release notes - I'll try and get that > sorted asap - > in the meantime this blog post pretty much covers it - > http://blog.floehopper.org/articles/2007/06/08/mocha-0-5-released. > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From justin at spiceworks.com Tue Jun 12 17:31:55 2007 From: justin at spiceworks.com (Justin Perkins) Date: Tue, 12 Jun 2007 16:31:55 -0500 Subject: [mocha-developer] replacement for returning Proc Message-ID: <3C9FEF06-B4E1-4242-8E6A-09DFB8D8EA5A@spiceworks.com> Can somebody help me understand the new syntax for replacing a return statement that returns a Proc? I'm having difficulty understanding what is meant by: "Use explicit multiple return values and/or multiple expectations instead." source: http://mocha.rubyforge.org/classes/Mocha/ Expectation.html#M000024 Here is a simple example of what I am doing: http:// pastie.textmate.org/69923 Thanks, Justin From pbattley at gmail.com Wed Jun 13 12:15:16 2007 From: pbattley at gmail.com (Paul Battley) Date: Wed, 13 Jun 2007 17:15:16 +0100 Subject: [mocha-developer] Mocking system/` In-Reply-To: <3D2AFC5E-B680-4B29-9F91-E9298C645CF4@gmail.com> References: <1151082.1181625484917.JavaMail.oracle@procap02.its.calpoly.edu> <1B6F4EC8-F315-4F3F-B4E2-EE2D5F1D3763@gmail.com> <3D2AFC5E-B680-4B29-9F91-E9298C645CF4@gmail.com> Message-ID: <2ab6a5020706130915t1acb18f0oe070355eb0b5c61a@mail.gmail.com> On 12/06/07, Jonathan Younger wrote: > Yup, it's working fine for me. Interesting stuff. I stand corrected! Paul. From jamesmead44 at gmail.com Wed Jun 13 12:46:45 2007 From: jamesmead44 at gmail.com (James Mead) Date: Wed, 13 Jun 2007 17:46:45 +0100 Subject: [mocha-developer] replacement for returning Proc In-Reply-To: <3C9FEF06-B4E1-4242-8E6A-09DFB8D8EA5A@spiceworks.com> References: <3C9FEF06-B4E1-4242-8E6A-09DFB8D8EA5A@spiceworks.com> Message-ID: <1db558f00706130946n194b6da8r610d96713c6caca5@mail.gmail.com> Hi Justin, Thanks for your question. It's great to have an example test to talk around. As you've noticed, using Expectation#returns with an instance of a Proc is deprecated in version 0.5 of Mocha. There is no drop-in replacement for this usage. Let me try and explain why... 1) Currently you can't easily return an instance of a Proc. Once the current usage has been removed in the next release, we'll be able to do the following which seems more logical and consistent... proc = Proc.new object = mock() object.stubs(:method).returns(proc) assert_equal proc, object.method 2) The current usage encourages the use of complex logic for computing return values which is not sensible mocking practice. Return values should really be explicitly defined by the test. The newer version of Mocha gives much more flexibility in doing this e.g. you can do... Time.stubs(:now).returns(time_1) Time.now # => time_1 Time.stubs(:now).returns(time_2) Time.now # => time_2 m = mock() m.stubs(:method).returns(1, 2, 3).then.raises('error').then.returns(5, 6) Although the ideas above will solve many scenarios, they won't directly solve your problem. In your example, you expect a call to the operation_with_render method, but still want some of the side effects of the method to occur (i.e. the call to the render method). Can you explain more about why you need this? Can you flesh out your example a little bit more, so I understand what you are trying to achieve. Alternatively could you move the call to the rendermethod outside the operation_with_render method? Presumably your example test is a Rails controller test in real life...? Cheers, James. -- http://blog.floehopper.org From jamesmead44 at gmail.com Wed Jun 13 12:53:41 2007 From: jamesmead44 at gmail.com (James Mead) Date: Wed, 13 Jun 2007 17:53:41 +0100 Subject: [mocha-developer] advice on new failures with 0.5.0 In-Reply-To: <047B0091-6E32-4248-ABEF-CBB4A5FD952D@spiceworks.com> References: <1db558f00706121132g545261a1l4676eb4561e6663f@mail.gmail.com> <047B0091-6E32-4248-ABEF-CBB4A5FD952D@spiceworks.com> Message-ID: <1db558f00706130953q62822a21q6cf704e36d32dbc6@mail.gmail.com> On 12/06/07, Justin Perkins wrote: > > In trying to make a small, reproducible test case (that passed every > time) I discovered an error (surprise) in our code that wasn't > discovered by the previous version of Mocha. This new exception led > me to wrongly accuse Mocha. All is well and we are happily using > 0.5.0 now. > Cool. -- James. http://blog.floehopper.org From justin at spiceworks.com Wed Jun 13 13:11:32 2007 From: justin at spiceworks.com (Justin Perkins) Date: Wed, 13 Jun 2007 12:11:32 -0500 Subject: [mocha-developer] replacement for returning Proc In-Reply-To: <1db558f00706130946n194b6da8r610d96713c6caca5@mail.gmail.com> References: <3C9FEF06-B4E1-4242-8E6A-09DFB8D8EA5A@spiceworks.com> <1db558f00706130946n194b6da8r610d96713c6caca5@mail.gmail.com> Message-ID: <74AEFD94-5A06-4733-A755-597DDF8563F0@spiceworks.com> Thanks for your reply James. As you have discovered by looking at the example, the method we are trying to mock is not simply returning a basic value, it is calling the Rails render method. When this method (the one which calls the render method) is mocked, then no call to render occurs and Rails throws an exception because every action MUST have a render of some kind (unless I am mistaken). The obvious solution here is to re-factor our code to not rely on the render method being called from the helper method and instead have it return a string of text, which it will then pass to the render method. Unfortunately this is not the ideal solution for us at this time since it involves changing quite a bit of code. For now we can deal with deprecation warnings until a time (hopefully in a month or so) when we can clean up this code to not be so dependent on the render method. Thanks again, justin On Jun 13, 2007, at 11:46 AM, James Mead wrote: > Hi Justin, > > Thanks for your question. It's great to have an example test to > talk around. > > As you've noticed, using Expectation#returns with an instance of a > Proc is > deprecated in version 0.5 of Mocha. There is no drop-in replacement > for this > usage. Let me try and explain why... > > 1) Currently you can't easily return an instance of a Proc. Once > the current > usage has been removed in the next release, we'll be able to do the > following which seems more logical and consistent... > > proc = Proc.new > object = mock() > object.stubs(:method).returns(proc) > assert_equal proc, object.method > > 2) The current usage encourages the use of complex logic for computing > return values which is not sensible mocking practice. Return values > should > really be explicitly defined by the test. The newer version of > Mocha gives > much more flexibility in doing this e.g. you can do... > > Time.stubs(:now).returns(time_1) > Time.now # => time_1 > Time.stubs(:now).returns(time_2) > Time.now # => time_2 > > m = mock() > m.stubs(:method).returns(1, 2, 3).then.raises > ('error').then.returns(5, 6) > > Although the ideas above will solve many scenarios, they won't > directly > solve your problem. > > In your example, you expect a call to the operation_with_render > method, but > still want some of the side effects of the method to occur (i.e. > the call to > the render method). Can you explain more about why you need this? > Can you > flesh out your example a little bit more, so I understand what you are > trying to achieve. Alternatively could you move the call to the > rendermethod outside the > operation_with_render method? > > Presumably your example test is a Rails controller test in real > life...? > > Cheers, James. > -- > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From james.mead at mail.com Fri Jun 15 05:49:58 2007 From: james.mead at mail.com (James Mead) Date: Fri, 15 Jun 2007 10:49:58 +0100 Subject: [mocha-developer] Fwd: [ mocha-Patches-11583 ] Mocha 0.5.0 throwing unexpected warnings, one line patch included References: <20070615094408.2CBFC52409AF@rubyforge.org> Message-ID: <4BB42492-C15C-4565-AB29-92C203BDE59E@mail.com> Begin forwarded message: > From: > Date: 15 June 2007 10:44:07 BDT > To: noreply at rubyforge.org > Subject: [ mocha-Patches-11583 ] Mocha 0.5.0 throwing unexpected > warnings, one line patch included > > Patches item #11583, was opened at 2007-06-14 21:28 > You can respond by visiting: > http://rubyforge.org/tracker/? > func=detail&atid=7479&aid=11583&group_id=1917 > > Category: None > Group: None >> Status: Closed >> Resolution: Accepted > Priority: 3 > Submitted By: Glenn Rempe (grempe) > Assigned to: Nobody (None) > Summary: Mocha 0.5.0 throwing unexpected warnings, one line patch > included > > Initial Comment: > Hello. > > The tests for my application run clean with mocha 0.4.0. I > upgraded one of my machines to 0.5.0 with a new install of mocha > and suddenly my unchanged tests were throwing a warning like: > > mac-mini:~/src/svk/amazon-ec2/trunk/amazon-ec2 glenn$ /usr/local/ > bin/ruby -w -Ilib:ext:bin:test -e 'require "test/test_EC2.rb"; > require "test/test_EC2_console.rb"; require "test/ > test_EC2_image_attributes.rb"; require "test/test_EC2_images.rb"; > require "test/test_EC2_instances.rb"; require "test/ > test_EC2_keypairs.rb"; require "test/test_EC2_responses.rb"; > require "test/test_EC2_security_groups.rb"; require "test/ > test_EC2_version.rb"; require "test/test_helper.rb"; require "test/ > unit"' > Loaded suite -e > Started > ..../usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.0/lib/mocha/mock.rb: > 151: warning: instance variable @responder not initialized > /usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.0/lib/mocha/mock.rb: > 151: warning: instance variable @responder not initialized > /usr/local/lib/ruby/gems/1.8/gems/mocha-0.5.0/lib/mocha/mock.rb: > 151: warning: instance variable @responder not initialized > > This seems to be related to the fact that I am not calling a new > method in 0.5.0 Mock#responds_like in mock.rb in my tests. Since I > never call this in my tests the @responder instance variable is > never set and the method_missing call throws a warning since you > are doing a test on an unset variable. > > Not sure if this is the perfect fix or not, but when I defined > @responder = nil in the initialization of the mock.rb file all > warnings in my tests went away and all of your tests still pass. > > Please take a look at the single line patch for implementation and > please also enhance the documentation and examples to show how > responds_like is supposed to be used. > > Thanks, > > Glenn > > ---------------------------------------------------------------------- > >> Comment By: James Mead (jamesmead) > Date: 2007-06-15 09:44 > > Message: > Many thanks. You are quite right. I had forgotten about the > responds_like functionality. I'm not 100% sure it's complete! I've > fixed the warning and switched warnings on in the rake test tasks > to highlight similar problems in the future. I've published a new > set of files for version 0.5.1 to include this fix (http:// > rubyforge.org/frs/?group_id=1917). > > In what way do you think the rdoc for responds_like is not > complete? http://mocha.rubyforge.org/classes/Mocha/Mock.html#M000029 > > Thanks again for your input. > > ---------------------------------------------------------------------- > > You can respond by visiting: > http://rubyforge.org/tracker/? > func=detail&atid=7479&aid=11583&group_id=1917 From j at jonathanleighton.com Sun Jun 17 17:50:14 2007 From: j at jonathanleighton.com (Jonathan Leighton) Date: Sun, 17 Jun 2007 22:50:14 +0100 Subject: [mocha-developer] Testing a call to super Message-ID: <1182117014.5968.0.camel@localhost.localdomain> Hi, Is there or could there be any way to test that a method calls "super"? Thanks -- Jonathan Leighton, Web Developer http://jonathanleighton.com/ From jamesmead44 at gmail.com Mon Jun 18 04:45:10 2007 From: jamesmead44 at gmail.com (James Mead) Date: Mon, 18 Jun 2007 09:45:10 +0100 Subject: [mocha-developer] Testing a call to super In-Reply-To: <1182117014.5968.0.camel@localhost.localdomain> References: <1182117014.5968.0.camel@localhost.localdomain> Message-ID: <1db558f00706180145o159fc375y54deb416e06f6e44@mail.gmail.com> I can't think of a simple way offhand. Can you give an example (both test & application code) to explain why you want to do it? -- James. http://blog.floehopper.org From anselm at netuxo.co.uk Tue Jun 19 09:17:26 2007 From: anselm at netuxo.co.uk (Anselm Heaton) Date: Tue, 19 Jun 2007 14:17:26 +0100 Subject: [mocha-developer] Changing the value of $? Message-ID: <4677D766.1050002@netuxo.co.uk> Hi :) Does anyone know of a way to set the value of $? ? I have a test which stubs ` ; the call works fine, but then the library I am testing checks the value of $? to see if the process terminated correctly. It seems not to be possible to assign $? directly... For now I do this before my test : `ls > /dev/null` Which ensure that $? is zero ; but this is not a very nice way of doing it ! If anyone here has a good trick for this, it will be very welcome :) Thanks, Anselm -- ------------------------------ Netuxo Ltd a workers' co-operative providing low-cost IT solutions for peace, environmental and social justice groups and the radical NGO sector Registered as a company in England and Wales. No 4798478 Registered office: 5 Caledonian Road, London N1 9DY, Britain ------------------------------ email office at netuxo.co.uk http://www.netuxo.co.uk ------------------------------ From jamesmead44 at gmail.com Tue Jun 19 09:51:12 2007 From: jamesmead44 at gmail.com (James Mead) Date: Tue, 19 Jun 2007 14:51:12 +0100 Subject: [mocha-developer] Changing the value of $? In-Reply-To: <4677D766.1050002@netuxo.co.uk> References: <4677D766.1050002@netuxo.co.uk> Message-ID: <1db558f00706190651m647c460fn426853efdbf527ac@mail.gmail.com> The only thing I can suggest is to wrap the $? execution environment variable in a method e.g. exit_status(). Then you could then stub the exit_status() method to return your desired result. -- James. http://blog.floehopper.org From kevin.clark at gmail.com Tue Jun 19 19:30:12 2007 From: kevin.clark at gmail.com (Kevin Clark) Date: Tue, 19 Jun 2007 16:30:12 -0700 Subject: [mocha-developer] Changing the value of $? In-Reply-To: <1db558f00706190651m647c460fn426853efdbf527ac@mail.gmail.com> References: <4677D766.1050002@netuxo.co.uk> <1db558f00706190651m647c460fn426853efdbf527ac@mail.gmail.com> Message-ID: This is working for me, right now: $?.stubs(:exitstatus).returns(0) also (though I know the proc version is deprecated) : Job.any_instance.expects(:`).with() {|call| call =~ /ssh/ }.returns(lambda { $?.expects(:exitstatus).returns(-1) '11807' }) On 6/19/07, James Mead wrote: > The only thing I can suggest is to wrap the $? execution environment > variable in a method e.g. exit_status(). Then you could then stub the > exit_status() method to return your desired result. > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > -- Kevin Clark http://glu.ttono.us From jamesmead44 at gmail.com Wed Jun 20 04:39:41 2007 From: jamesmead44 at gmail.com (James Mead) Date: Wed, 20 Jun 2007 09:39:41 +0100 Subject: [mocha-developer] Changing the value of $? In-Reply-To: References: <4677D766.1050002@netuxo.co.uk> <1db558f00706190651m647c460fn426853efdbf527ac@mail.gmail.com> Message-ID: <1db558f00706200139l6bec3e63sff70b35c90104631@mail.gmail.com> On 20/06/07, Kevin Clark wrote: > > $?.stubs(:exitstatus).returns(0) > That's interesting - I didn't think that would work, because $? is normally nil, but of course it does, because nil is an object in Ruby :-) -- James. http://blog.floehopper.org From anselm at netuxo.co.uk Wed Jun 20 07:48:50 2007 From: anselm at netuxo.co.uk (anselm at netuxo.co.uk) Date: Wed, 20 Jun 2007 12:48:50 +0100 (BST) Subject: [mocha-developer] Changing the value of $? In-Reply-To: <1db558f00706200139l6bec3e63sff70b35c90104631@mail.gmail.com> References: <4677D766.1050002@netuxo.co.uk> <1db558f00706190651m647c460fn426853efdbf527ac@mail.gmail.com> <1db558f00706200139l6bec3e63sff70b35c90104631@mail.gmail.com> Message-ID: <10873.86.144.199.194.1182340130.squirrel@www.netuxo.co.uk> On 20/06/07, Kevin Clark wrote: > > $?.stubs(:exitstatus).returns(0) > > Thanks for that one :) Anselm -- ------------------------------ Netuxo Ltd a workers' co-operative providing low-cost IT solutions for peace, environmental and social justice groups and the radical NGO sector Registered as a company in England and Wales. No 4798478 Registered office: 5 Caledonian Road, London N1 9DY, Britain ------------------------------ email office at netuxo.co.uk http://www.netuxo.co.uk ------------------------------ From steve.eichert at gmail.com Wed Jun 20 23:39:22 2007 From: steve.eichert at gmail.com (Steve Eichert) Date: Wed, 20 Jun 2007 23:39:22 -0400 Subject: [mocha-developer] expects with returns that returns the return value of the actual method Message-ID: I'm trying to test some code that's using active_merchant using the following test. What I'd like to be able to do is verify that purchase is called, however, rather than specifying the return value for purchase with returns, I'd like it to return the actual return value provided if you called the non mocked purchase method. Is this possible? def test_charge gateway = ActiveMerchant::Billing::Base.gateway(:bogus).new ActiveMerchant::Billing::Base.mode = :test member = Member.new member.credit_card_number = "1" member.expiration_date = "9/19/2007" member.payment_method = "bogus" member.first_name = "Steve" member.last_name = "Eichert" member.expects(:active_merchant_gateway).returns(gateway) # gateway.expects(:purchase).returns(:non_mocked_return) member.charge assert member.paid end From steve.eichert at gmail.com Wed Jun 20 23:55:08 2007 From: steve.eichert at gmail.com (Steve Eichert) Date: Wed, 20 Jun 2007 23:55:08 -0400 Subject: [mocha-developer] only checking certain parameters for a method Message-ID: I'm writing a test where I only care about one of the parameters being sent to the method, does anyone think having a way to say that any value for a parameter which I don't care about is valid? I'm thinking something like: def test_charge_is_for_10_bucks gateway = test_gateway member = Member.new member.credit_card_number = "1" member.expiration_date = "9/19/2007" member.payment_method = "bogus" member.first_name = "Steve" member.last_name = "Eichert" member.expects(:active_merchant_gateway).returns(gateway) member.expects(:purchase).with(1000, :any).returns(TestResponse.new) member.charge end On a slightly unrelated note, I was trying to find a way to search the mailing list archives here: http://rubyforge.org/pipermail/mocha-developer/but wasn't able to figure anything out. Does anyone have any suggestions? Cheers, Steve From jamesmead44 at gmail.com Thu Jun 21 04:49:21 2007 From: jamesmead44 at gmail.com (James Mead) Date: Thu, 21 Jun 2007 09:49:21 +0100 Subject: [mocha-developer] only checking certain parameters for a method In-Reply-To: References: Message-ID: <1db558f00706210149q597f5531j31ca7d1d72277b10@mail.gmail.com> You should be able to use the anything parameter matcher to do what you want (http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000009). i.e. member.expects(:purchase).with(1000, anything).returns(TestResponse.new ) -- James. http://blog.floehopper.org From jamesmead44 at gmail.com Thu Jun 21 04:54:27 2007 From: jamesmead44 at gmail.com (James Mead) Date: Thu, 21 Jun 2007 09:54:27 +0100 Subject: [mocha-developer] only checking certain parameters for a method In-Reply-To: References: Message-ID: <1db558f00706210154m31b14403ua7c92cf12dfba6a4@mail.gmail.com> On 21/06/07, Steve Eichert wrote: > > On a slightly unrelated note, I was trying to find a way to search the > mailing list archives here: > http://rubyforge.org/pipermail/mocha-developer/but wasn't able to > figure anything out. Does anyone have any suggestions? > How about googling for "site:rubyforge.org/pipermail/mocha-developer/{search}" replacing {search} with your search keywords. -- James. http://blog.floehopper.org From jamesmead44 at gmail.com Thu Jun 21 05:00:23 2007 From: jamesmead44 at gmail.com (James Mead) Date: Thu, 21 Jun 2007 10:00:23 +0100 Subject: [mocha-developer] expects with returns that returns the return value of the actual method In-Reply-To: References: Message-ID: <1db558f00706210200g3f3f170qa2fbb189cc932d17@mail.gmail.com> While it would be technically possible, Mocha doesn't support this. I doubt it ever will because what you describe is not really what mocking is all about. Why do you want to get the real result? Can you not record a sample result and then use this as a canned result in the test? -- James. http://blog.floehopper.org From steve.eichert at gmail.com Thu Jun 21 08:05:57 2007 From: steve.eichert at gmail.com (Steve Eichert) Date: Thu, 21 Jun 2007 08:05:57 -0400 Subject: [mocha-developer] only checking certain parameters for a method In-Reply-To: <1db558f00706210149q597f5531j31ca7d1d72277b10@mail.gmail.com> References: <1db558f00706210149q597f5531j31ca7d1d72277b10@mail.gmail.com> Message-ID: Perfect, thanks! I realized after I sent the question about trying to search that I could just use google with site: to do what I wanted. Sorry for being lame :) On 6/21/07, James Mead wrote: > > You should be able to use the anything parameter matcher to do what you > want > (http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000009). > > i.e. member.expects(:purchase).with(1000, anything).returns( > TestResponse.new > ) > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > From steve.eichert at gmail.com Thu Jun 21 08:09:39 2007 From: steve.eichert at gmail.com (Steve Eichert) Date: Thu, 21 Jun 2007 08:09:39 -0400 Subject: [mocha-developer] expects with returns that returns the return value of the actual method In-Reply-To: <1db558f00706210200g3f3f170qa2fbb189cc932d17@mail.gmail.com> References: <1db558f00706210200g3f3f170qa2fbb189cc932d17@mail.gmail.com> Message-ID: In my specific example I want to use the real result because the real result being used is already a "fake" object that is returning canned results depending on the inputs. I'm trying to test some logic that's making use of active_merchant, and am using their "bogus" gateway that returns success/failures depending on predefined input. I can definitely go the route you mentioned and record a sample result, I was just hoping I could re-use the already implemented logic. I actually think that breaking my tests apart to test more specific things per test will help as well. Thanks, Steve On 6/21/07, James Mead wrote: > > While it would be technically possible, Mocha doesn't support this. I > doubt > it ever will because what you describe is not really what mocking is all > about. > > Why do you want to get the real result? Can you not record a sample result > and then use this as a canned result in the test? > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer > From zach.lists at gmail.com Thu Jun 21 09:55:17 2007 From: zach.lists at gmail.com (Zach Moazeni) Date: Thu, 21 Jun 2007 09:55:17 -0400 Subject: [mocha-developer] With Parameter Block Message-ID: <3E9A1762-5F67-4CFC-9303-0A8F1F3737A8@gmail.com> I'm curious why the Parameter block check for the with is going to be removed. I like the concept of clean, readable tests, however I also like to test as efficiently as possible. For some tests, I'll take the approach of putting test assertions inside the parameter block, and always returning true. This is a contrived example: def test_something mock = mock("some_mock") mock.expects(:foo).with do | param_that_is_a_string, param_that_is_a_model | assert_match(/something-for1/, param_that_is_a_string) assert param_that_is_a_model.valid? true end.returns("blah") end Again, I'm not against code readability, but I do prefer to be able to write my tests explicitly instead of creating a matcher for each special case. -Zach From jamesmead44 at gmail.com Fri Jun 22 06:33:32 2007 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 22 Jun 2007 11:33:32 +0100 Subject: [mocha-developer] With Parameter Block In-Reply-To: <3E9A1762-5F67-4CFC-9303-0A8F1F3737A8@gmail.com> References: <3E9A1762-5F67-4CFC-9303-0A8F1F3737A8@gmail.com> Message-ID: <1db558f00706220333m121ba83brdf0bb91a12e58b88@mail.gmail.com> Hi Zach, I'm not fixed on the idea of the block check going away. It's great to have your example usage. You are right that readability is one advantage of the parameter matcher classes, but another benefit is hopefully more useful error messages. Maybe the solution is to have a custom matcher which takes a block. What do you think? I'll give it some more thought. -- James. http://blog.floehopper.org From dan at tastapod.com Fri Jun 22 08:26:44 2007 From: dan at tastapod.com (Dan North) Date: Fri, 22 Jun 2007 13:26:44 +0100 Subject: [mocha-developer] With Parameter Block In-Reply-To: <1db558f00706220333m121ba83brdf0bb91a12e58b88@mail.gmail.com> References: <3E9A1762-5F67-4CFC-9303-0A8F1F3737A8@gmail.com> <1db558f00706220333m121ba83brdf0bb91a12e58b88@mail.gmail.com> Message-ID: <467BC004.5050307@tastapod.com> James Mead wrote: > Hi Zach, > > I'm not fixed on the idea of the block check going away. It's great to have > your example usage. You are right that readability is one advantage of the > parameter matcher classes, but another benefit is hopefully more useful > error messages. Maybe the solution is to have a custom matcher which takes a > block. What do you think? > > I'll give it some more thought. > I agree - having a custom matcher that knows about procs is a cleaner solution than having the whole proc thing baked into expectations. Expecting a proc is an edge case when you are mostly mocking services. It's normally simple value objects like strings that get passed in as parameters. Cheers, Dan From zach.lists at gmail.com Fri Jun 22 12:43:47 2007 From: zach.lists at gmail.com (Zach Moazeni) Date: Fri, 22 Jun 2007 12:43:47 -0400 Subject: [mocha-developer] With Parameter Block In-Reply-To: <467BC004.5050307@tastapod.com> References: <3E9A1762-5F67-4CFC-9303-0A8F1F3737A8@gmail.com> <1db558f00706220333m121ba83brdf0bb91a12e58b88@mail.gmail.com> <467BC004.5050307@tastapod.com> Message-ID: <02ADD251-2996-4DB0-B4FE-1EA01B6CE3AA@gmail.com> James, Yeah that's fine with me. I'm really swamped now, but I'll try and work out something soon and submit a patch of what I'm thinking. I do want give kudos to the team for developing a nice mocking library. It hasn't been a silver bullet, but it does make my testing much easier. -Zach On Jun 22, 2007, at 8:26 AM, Dan North wrote: > James Mead wrote: >> Hi Zach, >> >> I'm not fixed on the idea of the block check going away. It's >> great to have >> your example usage. You are right that readability is one >> advantage of the >> parameter matcher classes, but another benefit is hopefully more >> useful >> error messages. Maybe the solution is to have a custom matcher >> which takes a >> block. What do you think? >> >> I'll give it some more thought. >> > I agree - having a custom matcher that knows about procs is a cleaner > solution than having the whole proc thing baked into expectations. > Expecting a proc is an edge case when you are mostly mocking services. > It's normally simple value objects like strings that get passed in as > parameters. > > Cheers, > Dan > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer