Hello

Personally I would say that `and_call_original` here should check the method 
visibility, are you using verifying doubles? By stubbing the method you are 
making it exist even if it did not, but given the additional modifier I wonder 
if we can improve this.

Cheers
Jon


Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk


On Wednesday, 4 July 2018 at 15:21, [email protected] wrote:

> Hello,
> 
> I just had a false negative (test reported as OK while feature was actually 
> broken) when expecting a method call on a nested service object because the 
> method was private, but after applying an `expect_any_instance_of` the method 
> call was made public and caused the test to pass (despite calling 
> `and_call_original`
> 
> Here is a sample way to repro
> 
> class Foo
>   private
>  
>   def method_meant_to_be_public
>   end
> end
> 
> 
> class FooJob < ActiveJob::Base
>   def perform
>     Foo.new.method_meant_to_be_public
>   end
> end
> 
> 
> 
> Performing a FooJob indeed causes a crash with
> 
> private method `method_meant_to_be_public' called for #<Foo:0x00000003f58c98>
> 
> 
> However my spec was, on first sight, not failing
> 
> describe FooJob do 
>   it 'triggers warmup failure for the pro' do
>       expect_any_instance_of(Foo).to 
> receive(:method_meant_to_be_public).and_call_original
>       FooJob.perform_now
>     end
> end
> 
> 
> I am wondering if this is expected behavior or if I should report it as a bug 
> ? It is not really obvious that using expect_any_instance_of would override 
> the public/private status of methods...
> 
> 
> -- 
> 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] 
> (mailto:[email protected]).
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/68928338-36a4-472c-8dd5-f685613e6750%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/rspec/68928338-36a4-472c-8dd5-f685613e6750%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/34E9166F2A5248C5BF25588BE62BBFE4%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to