Search code examples
ruby-on-railsrubyruby-on-rails-3rspecrspec2

RSpec: Stub private method


I try to test a class with RSpec2, that has some private methods, which are called from some public methods. I test the public methods with

@foo.should_receive(:start_training).exactly(2).times

if they are called and how often. My problem is, that this approach doesn't work with private methods. So, is there any way to use sth like @foo.send(:private_method) in combination with should_receive? Or any other syntax?


Solution

  • should_receive(:method) works whether the visibility of :method is public or private.