What's the best way to unit test protected & private methods in Ruby?

后端 未结 16 623
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 10:47

What\'s the best way to unit test protected and private methods in Ruby, using the standard Ruby Test::Unit framework?

I\'m sure somebody will pipe up a

16条回答
  •  生来不讨喜
    2020-12-12 11:25

    One way I've done it in the past is:

    class foo
      def public_method
        private_method
      end
    
    private unless 'test' == Rails.env
    
      def private_method
        'private'
      end
    end
    

提交回复
热议问题