mutant icon indicating copy to clipboard operation
mutant copied to clipboard

module_function handling in mutant is on instance

Open tjchambers opened this issue 9 years ago • 6 comments

Wanted to make note that if module_function is specified in a module, that the specifications in corresponding spec files must use '#bar' and not '.bar':

describe '#bar' do
...
end

as the methods have to kill the mutations on the instance where they are defined rather than on the singleton where the module_function places the aliases.

tjchambers avatar Oct 21 '15 21:10 tjchambers

@tjchambers thanks this is a helpful note since the way module_function copies methods isn't obvious. Would you be able to share more information about how this test looks? Testing the instance method should be tricky since mixing it into a class or module results in it being a private method.

If @mbj agrees I think documenting the quirkiness of testing a module_function method might makes sense.

backus avatar Dec 22 '15 19:12 backus

Similar issue for reference: https://github.com/mbj/mutant/issues/121

backus avatar Dec 22 '15 19:12 backus

@backus - on the advice of @mbj I eliminated all module_function references and was more specific.

So I don't have any specs that require me to handle this issue. If I recall however (it's been a while) after I convert to specifying the instance method it just worked. I think it has to do with the spec matching in mutant when examining the methods under test. I may be incorrect about that. I don't recall it being a private method of the instance, but rather the class? I do not recall anywhere I used it as a mixin, but as a shortcut to adding self. prefix.

tjchambers avatar Dec 22 '15 20:12 tjchambers

Ah alright that made sense. How did you eliminate your module_function usage specifically? Did you switch to something like extend self or did you just not need module_function in the first place?

backus avatar Dec 22 '15 20:12 backus

My recall is I dropped the module_function and prefixed the method defs with self.

tjchambers avatar Dec 22 '15 20:12 tjchambers

I just encountered this issue. Specifiying the instance method doesn't work. I suppose you have to actually call the method as an instance method.

mvz avatar Jul 09 '16 10:07 mvz