user1771103
user1771103

Reputation: 71

rspec - stub included methods

I need to stub a helper method that's included inside a controller. Yes it's bad practice but for now that's what what i have to live with.

class ApplicationController < ActionController::Base
  include ApplicationHelper 

Say application_helper has a method :foo that's included inside the controller. I've tried stubbing like:

  1. controller.stub(:foo)
  2. @helper = Object.new.extend ApplicationHelper; @helper.stub(:foo)

Upvotes: 2

Views: 275

Answers (1)

Kenrick Chien
Kenrick Chien

Reputation: 1046

I've had success with this before:

@controller.stub(:foo)

Notice the @ before the controller.

Upvotes: 1

Related Questions