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/e72e42a8-0b4c-4227-ba80-d58afda499b9o%40googlegroups.com.

Reply via email to