is there anyway to mock a cf method such as cfsche...
# box-products
t
is there anyway to mock a cf method such as cfschedule or cfdirectory using querySim() other than wrapping it in a function?
b
Yes
t
excellent news, any clues 😉
b
Basically, if you have something like a cfdirectory in your code, wrap it in a utility function, then you can mock just that function
t
doesn't that make your previous answer invalid brad?
b
Sorry, I misread your original question. I thought you were asking if you could mock those tags by wrapping them in a function
The answer to whether you can mock built-in tags in the language is no 🙂
Well, it may be possible to install your own custom tags that override the built in tags if you're using Lucee, but I've never done that and it would likely break the test framework
t
yes I was trying to reduce the amount of refactoring rather than introduce further obstacles
but I have an answer so thank you and enjoy camp
a
one should "always", right from the start, put any code that hits an external service into its own adapter. I realise this is a bit "oh if you wanted to get to there, I wouldn't start from here", but it's a good reminder that all these design patterns that have been around for ages exist for a reason. That said, it takes close to zero effort to abstract a
<cfdirectory>
call into its own private method even within the same class the original call was in. No need to do ALL OF THEM at once. Just refactor the one that's giving you shit now. There's no need to not improve one's code slightly by deciding there's a monolithic task to solve every instance of that code that could stand to be improved.