I managed to find another way, other than monkeypatching my class: using mocha to stub in this particular test.
RSpec.configure do |config| config.mock_framework = :mocha end before :each do CnuConfig.stubs(:test).returns(new_config)) #works 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/-/_7FlcVDuktkJ. For more options, visit https://groups.google.com/groups/opt_out.
