tag:blogger.com,1999:blog-12467669.post3293099249203134471..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: Ruby: Default method arguments to instance variablesJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-12467669.post-50811525712644057042007-04-12T08:55:00.000-04:002007-04-12T08:55:00.000-04:00I am testing what I think I'm testing; however, I'...I am testing what I think I'm testing; however, I've only shown one test. I would also have another test that ensured that the instance variable was used when 'on()' was called.<BR/><BR/>This isn't a pattern to be used all the time. The example I gave tests the state of battery, but it could just as easily be a variable that's a Fixnum. And, using the class normally that might mean that the variable could only be positive, but I want to test my method with a negative number. You could use instance_variable_set, but that doesn't seem cleaner than this option since it's strongly relying on the internals of the class.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-56307884069352909342007-04-12T08:30:00.000-04:002007-04-12T08:30:00.000-04:00Are you testing what you think you're testing?You ...Are you testing what you think you're testing?<BR/><BR/>You appear to be testing the behaviour of 'on(an_arg)', but your app actually <I>uses</I> 'on()'.<BR/><BR/>This aspect of mock based testing is where I start to get uncomfortable; you're making assertions about both the 'front' and the 'back' of the method, and you just made your application that much more brittle because of it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-49804841319514229892007-04-12T06:49:00.000-04:002007-04-12T06:49:00.000-04:00Bryan, Yes, I always feel uneasy about modifying a...Bryan, Yes, I always feel uneasy about modifying application code simply for testing. But, when it is necessary I'll do it without hesitation to ensure that I have a better tested application.<BR/><BR/>I was recently taking with John Hume about this issue and he said that if I needed this technique I probably had a design issue in my class. He's probably right, and you should start there before using this trick. However, if you determine your design is sound, I think this is a nice trick to know.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-47384535798873687032007-04-12T05:17:00.000-04:002007-04-12T05:17:00.000-04:00@bryan - bah! Worry is for management :)@bryan - bah! Worry is for management :)Dr Nichttps://www.blogger.com/profile/17833227514368162020noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-78404342047948500752007-04-11T21:34:00.000-04:002007-04-11T21:34:00.000-04:00Do you worry about modifying application code for ...Do you worry about modifying application code for the sole purpose of your tests?Unknownhttps://www.blogger.com/profile/10534247996801206864noreply@blogger.com