From: Dossy Date: 2002-05-10T05:38:43+09:00 Subject: Test::Unit::Assertions #assert_takes and #assert_takes_nowait (was Re: Thread#join doesn't accept a timeout?) On 2002.05.10, Nathaniel Talbott wrote: > Dossy [mailto:dossy@panoptic.com] wrote: > > > I did try using the timeout extension, but this just doesn't > > seem to work: > > > > timeout(@timeout) { send(@method_name) } > > > > I'm busy right now, so wrapping my mind around why it isn't > > working will have to wait until later. It's probably > > something simple, but I'm having a stupid moment right now. > > The timeout call should block until the send either finishes, or passes > the timeout value. If the latter, the exception will fire. What's > happening when you run it? Are you expecting the call to be > non-blocking? To be honest, I can't remember. Thanks to your assert_takes, I don't have to remember, either. :-) > > Of course, I just realized yet another reason why Ruby rules > > ... I can extend the core without having to actually touch > > any of its files -- aah! I'm going to write an assert_xpath > > assertion to make my REXML-using test cases easier to write! > > God, this is great! > > I know... isn't it? It's completely ruined my enjoyment when coding > Java. Now that I'm getting into Ruby, I'll never code in Java if I can ever help it. Man, Ruby is going to spoil me ... ;-) not like that's a bad thing! > > I guess we could implement #assert_takes_nowait that has a > > timeout and all of my code can be thrown away. :-) What do > > you think? > > It sounds like I'm not the only one who finds this useful, so I'm going > to add it to the TODO (which is getting rather long lately). Thanks for > your input. I just wrote assert_takes_nowait, and slightly rewrote your assert_takes. Both are posted at the URL I mentioned earlier ... > > Nathaniel, I've posted my code (and unit tests) to this URL: > > > > http://panoptic.com/ruby > > You're a step ahead of me... I hadn't written tests for mine yet :-/ Ah, you're not Test Infected, huh? I always try to write tests for everything, first. It's the XP influence ... :-) > That's the only problem with Ruby - it's so easy to write, if you're not > careful you can end up writing the code before you realize there isn't a > test for it. At least that's how I rationalize it :-) It _is_ really easy to write ... which makes the tests even easier to write. You know how many hoops you have to jump through to write tests in other languages ... *grin* > BTW, your code makes me realize that we need better decorator support in > the framework, both implicit (as proposed earlier by Dave) and explicit. > I'll add that to the TODO as well. Cool. I'd be willing to help out, if I can. Like I said, I posted revised code and tests for assert_takes and assert_takes_nowait (since I first mentioned the URL) so you might want to double-check to make sure you saw the latest versions. Now, time to start working on the load test decorator ... ;-) -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)