how to check method calling in rspec

Jun 8, 2015

You can check a method is called or not by using receive in rspec.

describe "#method" do
  it "should call method_b" do
    @user = Persion.new
    expect(@user).to receive(:method_b)
    
    @user.method # method_b is called in method
  end
end
expect(@user).to receive(:method_b).once
expect(@user).to receive(:method_b).twice