ThomYorkkke
ThomYorkkke

Reputation: 2141

Stubbing a specific method in a controller with RSpec

I am trying to stub out a mixin method in my controller tests. The controller includes the SeatingChartCreator module, which has already been tested. So all I want to do is stub it out so that it sets the controller @errors variable to nil in one test, and to something in another, and then stub it out another time just to make sure that it gets called. I've looked over the RSpec documentation, and it seems like all they provide information on is stubbing a whole class, not just specific methods in the class I am testing.

Upvotes: 0

Views: 990

Answers (1)

infused
infused

Reputation: 24367

To stub a method use allow/receive. For example:

before do
  allow(controller).to receive(:say_hello).and_return('Hello!')
end

Upvotes: 1

Related Questions