Closed1

Testing a private module method in RSpec

nyancatnyancat

There are 2 ways to write a test for a private module method:

  1. Create an instance of a class that extends the target class, then use it as a double.
obj = Class.new { exted TargetClass }
allow(obj).to receive(:another_method)
obj.send(:private_method)
expect(obj).to have_received(:another_method)
  1. Include the target class at the top of the RSpec file, not recommended though.
include TargetClass

...
このスクラップは5ヶ月前にクローズされました