RSpec isn't doing anything special to create the behavior you're describing, and there's nothing we can do to prevent it. It's simply how Ruby modules and private methods work. Private methods are can be called as long as the implicit `self` receiver -- which means a private method from a superclass can be called from a subclass. Module inclusion puts the module into the ancestor chain of the including class, effectively making the module a superclass, allowing private methods in the module to be called from the including class.
HTH, Myron On Sat, May 6, 2017 at 9:18 AM, Evan Brodie <[email protected]> wrote: > Hello, > > In the application that I am working on, the rspec configuration includes > several modules that are "mixed-in" to rspec via config.include, in an > RSpec.configuration block. This would make all the instance methods of > that module available to my test classes. For example, I have the following > helper to abstract some of the login functionality in my acceptance tests: > > module LoginHelper > def login(user) > # Insert login logic here > end > end > > > The implementation of the login method has begun to grow and is starting > to include some duplicated code, so I naturally want to abstract some of > this duplication out into *private methods*, to ease code readability. > However, it appears that any private method included into my rspec > configuration from these "mixed-in" modules will also be visible to my test > code. I can verify this by placing a specific raise message into my private > method and witness that specific error message appear when the test calls > this method and ultimately fails. What I perhaps hoped was that the test > would instead fail due to a method scope issue. > > I am seeking a way to have methods from these "mixed-in" modules be hidden > from test code and only available to public methods from within its module, > so that I do not risk having these private methods get accidentally called > by the test code. Is there a way to accomplish this in the current version > of rspec? > > Thank you. > Evan > > -- > 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/ > msgid/rspec/c4cebf6d-b5a8-4c20-b2e4-7aa62824c3f5%40googlegroups.com > <https://groups.google.com/d/msgid/rspec/c4cebf6d-b5a8-4c20-b2e4-7aa62824c3f5%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/msgid/rspec/CADUxQmvUEM7kwe%3D5CbO_3%3DrkGCq3%2BNy%2B%3DULOie2%2B%2BLo6tWEHsg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
