Anshul Gupta
Anshul Gupta

Reputation: 83

How to test private helper(module) method in rspec

I have a helper module named "AppHelper" and private method "sum" which I want to test using rspec.

For example:

module AppHelper
 private
 def sum(a,b)
   puts a+b
 end
end

Upvotes: 0

Views: 1236

Answers (1)

sonal save
sonal save

Reputation: 118

ideally private methods can not test directly, it should be called from public method but here is a hack

create a dummy class and access private method using .send(:private_method, args)

example

obj = Class.new { extend AppHelper } obj.send(:sum, 1,2)

Upvotes: 3

Related Questions