[rspec-users] Failing to stub "test" in an object , because "test" is already defined in Kernel

Samer Masry smasry at dryblis.com
Tue Apr 9 20:54:58 UTC 2013


It's because :test was defined a private method and you're trying to access
it publicly

class Object
  private
    def test
    ...
    end
end

There are different approaches to testing private methods.
  http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
-or-
 you can test the methods that call the private method.


On Tue, Apr 9, 2013 at 1:35 PM, Constantin Gavrilescu <
comisarulmoldovan at gmail.com> 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?
>
>
>
> --
> Un fleac... m-au ciuruit.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
DryBlis - www.dryblis.com
Samer Masry | Rails Programmer
11 Ambler Ln, Emeryville, CA 94608
Tel.:510-991-7523 | Cel.: 714-814-8508
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130409/8158747e/attachment.html>


More information about the rspec-users mailing list