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

后端 未结 16 608
被撕碎了的回忆
被撕碎了的回忆 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:11

    Here's one easy way if you use RSpec:

    before(:each) do
      MyClass.send(:public, *MyClass.protected_instance_methods)  
    end
    

提交回复
热议问题