I believe it will work if you use a `double` rather than `Object.new`. 
 RSpec treats test doubles vs. partial mocks a bit different with respect 
to method visibility.  On a partial mock, rspec does not change the method 
visibility of existing methods...so since `test` is an existing private 
method on `Object`, it remains private.  A test double is treated as a 
"blank slate", and thus RSpec makes any method you stub on it public.

HTH,
Myron

On Tuesday, April 9, 2013 1:24:40 PM UTC-7, Constantin Gavrilescu wrote:
>
> I'm trying to stub the method "test" on an object, and I cannot do it with 
> rspec.
>
> Example with a simpler case:
>
>     o = Object.new
>     o.stub!(:test).and_return "lol"
>     o.test.should == "lol"
>
> Error:
>     Failure/Error: o.test.should == "lol" 
>     NoMethodError: private method `test' called for 
> #<Object:0x13cf47e4>    
>
> This is probably because Kernel implements #test and stubs are done with 
> method_missing.
> What's the recommended way to deal this this?
>

-- 
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/msg/rspec/-/1B3ha_6YX9QJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to