Myron, I see what you are saying. Thank you for giving me the technical
reason of why this doesn't work as expected for me.
I managed to make it work with rspec stubs. So rspec handles stubbing with
more delicacy, not changing visibility of the stubbed method, while mocha
takes the sledgehammer approach.
CnuConfig.stub(:test).and_return({"blah" => "blag"})
CnuConfig.public_class_method(:test) # YAY I can access my stub!
Regarding your point with using a double, I would like to to that I can't
do it here because I'm writing an integration test.
On Tuesday, April 9, 2013 4:53:21 PM UTC-5, Myron Marston wrote:
>
> 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/-/ao5je8pVrtIJ.
For more options, visit https://groups.google.com/groups/opt_out.