简体   繁体   中英

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)

I've had success with this before:

@controller.stub(:foo)

Notice the @ before the controller .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM