How to test a private method in rspec

Since you cannot access a private method directly, in order to test a private method, you can make use of the ‘send’ method that is available on all objects.

@obj = MyClass.new
result = @obj.send(:my_private_method, arguments)
expect(....)

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...