Hello David! 

This is a functional test on a legacy app and I do need to stub the method 
"test" on that object. The code that I'm testing is not easily testable. 

And I am actually trying to stub a a class method. This is what I came up 
with as a temporary working solution:

    class CnuConfig
      class_eval <<-EORUBY, __FILE__, __LINE__ + 1
        def self.test
           {"settings": "blah"}
        end
      EORUBY
    end



On Tuesday, April 9, 2013 3:31:34 PM UTC-5, [email protected] wrote:
>
> Hey Constantin,
>
> Hope you are well.
>
> I'd recommend not overriding Ruby's "test" method, or any core method. Got 
> a different name that works as well in context?
>
> Cheers,
> David
>
>
> On Tue, Apr 9, 2013 at 3:24 PM, Constantin Gavrilescu <
> [email protected] <javascript:>> 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] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/rspec/-/cd5FnRaMQJsJ.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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


Reply via email to