Phil, thanks for your reply. I agree that this was a fault of test coverage 
(I'm sure everyone agrees, not all tests in a test suite are as good as 
they can be, and there isn't enough time in the day to keep tests audited). 

I guess what I was looking to see if it was possible is to have rspec 
protect us from ourselves, definitely not a failing of RSpec specifically. 
Ideally I think what would be helpful is to be able to see if a stubbed 
method is being called in a public or private context, but that doesn't 
seem like something ruby can do (at least not easily or probably 
performantly). A warning on all stubbed private methods would probably 
generate a lot of unwanted noise, because it's standard practice to do 
write a test where you're *purposely* stubbing out a private method (for 
instance a method that does heavy processing or hits an external 
dependency).

So I guess the answer to my question of "can RSpec do this?" is probably 
"no". :)

Daniel

On Wednesday, July 22, 2020 at 12:56:13 PM UTC-4 [email protected] wrote:

>
>
> On Wednesday, July 22, 2020 at 3:55:00 AM UTC+3, Daniel Vandersluis wrote:
>>
>> Sorry my example was slightly off (pains of trying to anonymize!), 
>> because it's actually calling a (now) private method of a different class. 
>> Oops!
>>
>
> Thanks for taking the time, now I clearly understand what you mean.
>
> I don't see a problem with how you test `Operation`. It's your choice to 
> set the boundaries like that, and test it as a unit, avoiding testing 
> `Post#process`'s side effects.
> There's another problem, though. It's the coverage of `Post`. If you stub 
> the call to `Post#process` in one test, then you have to test what 
> `Post#process` does on its own.
> And here's where you'll be able to identify the issue. Just like your 
> program itself, RSpec won't be able to call `Post#process` from specs. 
> Meaning that if you write a test for it, it will tell that the method is 
> private.
> And you'll have to either opt-in for `post.public_send(:process)`. It is a 
> smell, as you're testing a private method.
> Sometimes, I believe, there's no other way around that. But in that case 
> you should clearly know what you are doing. Specifically, make sure you 
> don't stub this method anywhere.
>
> There seems nothing wrong to me with RSpec itself, it's about design of 
> the specs.
> Do you have an idea of something that would have helped you to identify 
> this issue earlier, like `config.warn_on_stubbing_private_methods!`?
>
> - Phil
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/c90859a2-eae7-4300-a5db-43ec468e9013n%40googlegroups.com.

Reply via email to