From jamesmead44 at gmail.com Fri Mar 28 12:13:21 2008 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 28 Mar 2008 16:13:21 +0000 Subject: [mocha-developer] how to test timeouts? that #returns deprecation again... In-Reply-To: <6a2b4fd00709051503y44171c30s3ea10e764efeef07@mail.gmail.com> References: <6a2b4fd00709051503y44171c30s3ea10e764efeef07@mail.gmail.com> Message-ID: <1db558f00803280913r705f1456wa602da050926237d@mail.gmail.com> I just found this old reply sitting in my drafts folder. I don't know if it's any use, but... Hmm. I don't like having multiple threads knocking around in my unit tests > (see http://www.jmock.org/threads.html - although its examples are in > Java, don't be put off - they are very readable). > > In this case you are really testing two things - firstly that you are > wrapping the call with a timeout and secondly that the timeout is working > correctly. I would suggest that the second issue is testing third party code > that you should be able to rely on (and ideally should have its own tests). > So in order to test the first issue, you could set up an expectation for the > call to Timeout::timeout. Unfortunately there isn't currently a nice way to > check that you are passing in the correct block to the timeout method. > > I'm going to mention this to James Adam (one of the other developers at > Reevoo) who ran into a similar issue a while ago - he might be able to help. > -- > James. > http://blog.floehopper.org > http://tumble.floehopper.org > From ryan.sobol at tobi.com Fri Mar 28 18:54:01 2008 From: ryan.sobol at tobi.com (Ryan Sobol) Date: Fri, 28 Mar 2008 15:54:01 -0700 Subject: [mocha-developer] mocking methods called multiple times Message-ID: <3CE9D0A8-1D91-47BD-B5A3-9ED6A73122BF@tobi.com> i'm trying to use a test dummy to block the interaction between my test and our database. the code im testing makes a handful of active_record calls (create_table, add_index, etc.) i'm trying to use mocks to expect calls at the database adapter level (i'm thinking #execute, but no committed to it yet) long story short, i'm having difficulties telling mocha to expect 2 calls to this method in the same test. thoughts? -- RYAN From jamesmead44 at gmail.com Fri Mar 28 19:30:34 2008 From: jamesmead44 at gmail.com (James Mead) Date: Fri, 28 Mar 2008 23:30:34 +0000 Subject: [mocha-developer] mocking methods called multiple times In-Reply-To: <3CE9D0A8-1D91-47BD-B5A3-9ED6A73122BF@tobi.com> References: <3CE9D0A8-1D91-47BD-B5A3-9ED6A73122BF@tobi.com> Message-ID: <1db558f00803281630p26bdd5aaofc9930ff6c9cfdbb@mail.gmail.com> On 28/03/2008, Ryan Sobol wrote: > > i'm trying to use a test dummy to block the interaction between my > test and our database. > > the code im testing makes a handful of active_record calls > (create_table, add_index, etc.) i'm trying to use mocks to expect > calls at the database adapter level (i'm thinking #execute, but no > committed to it yet) > > long story short, i'm having difficulties telling mocha to expect 2 > calls to this method in the same test. thoughts? Can you give us some more specifics? Ideally a simple test along with the code that it exercises? Try and keep it as simple as possible while still illustrating the point. It's always much easier to discuss concrete examples. Thanks. -- James. http://blog.floehopper.org http://tumble.floehopper.org From jay at jayfields.com Fri Mar 28 21:51:00 2008 From: jay at jayfields.com (Jay Fields) Date: Fri, 28 Mar 2008 21:51:00 -0400 Subject: [mocha-developer] mocking methods called multiple times In-Reply-To: <1db558f00803281630p26bdd5aaofc9930ff6c9cfdbb@mail.gmail.com> References: <3CE9D0A8-1D91-47BD-B5A3-9ED6A73122BF@tobi.com> <1db558f00803281630p26bdd5aaofc9930ff6c9cfdbb@mail.gmail.com> Message-ID: <9E6F49E1-8EB5-4645-9DE1-F3B5F4833072@jayfields.com> Examples are always nice, but in the mean time... Model.expects(:save).at_least_once will let you call it one or more times Model.stubs(:save) will let you call it zero or more times But, if you want to test models without hitting the database you can use UnitRecord. If you want to take it another level and test models without loading the Rails framework you can use arbs: http://arbs.rubyforge.org Cheers, Jay On Mar 28, 2008, at 7:30 PM, James Mead wrote: > On 28/03/2008, Ryan Sobol wrote: >> >> i'm trying to use a test dummy to block the interaction between my >> test and our database. >> >> the code im testing makes a handful of active_record calls >> (create_table, add_index, etc.) i'm trying to use mocks to expect >> calls at the database adapter level (i'm thinking #execute, but no >> committed to it yet) >> >> long story short, i'm having difficulties telling mocha to expect 2 >> calls to this method in the same test. thoughts? > > > Can you give us some more specifics? Ideally a simple test along > with the > code that it exercises? Try and keep it as simple as possible while > still > illustrating the point. It's always much easier to discuss concrete > examples. > > Thanks. > -- > James. > http://blog.floehopper.org > http://tumble.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer From jamesmead44 at gmail.com Sat Mar 29 04:57:18 2008 From: jamesmead44 at gmail.com (James Mead) Date: Sat, 29 Mar 2008 08:57:18 +0000 Subject: [mocha-developer] mocking methods called multiple times In-Reply-To: <9E6F49E1-8EB5-4645-9DE1-F3B5F4833072@jayfields.com> References: <3CE9D0A8-1D91-47BD-B5A3-9ED6A73122BF@tobi.com> <1db558f00803281630p26bdd5aaofc9930ff6c9cfdbb@mail.gmail.com> <9E6F49E1-8EB5-4645-9DE1-F3B5F4833072@jayfields.com> Message-ID: <1db558f00803290157q61884b57x9838998e21b66fbd@mail.gmail.com> Other possibilities... Model.expects(:create_table).times(2) # => must be called exactly twice # expect the same call twice Model.expects(:create_table).with(:table_1) # => once with one parameter Model.expects(:create_table).with(:table_2) # => once with another parameter -- James. http://blog.floehopper.org http://tumble.floehopper.org