[rspec-users] Stub a controller method containing arguments

jeevan reddy lists at ruby-forum.com
Sun Sep 9 06:00:25 UTC 2012


controller code:

class BooksController < ApplicationController
  def index
   param1, param2 = "123", "456"
    @test = method_1(param1, param2)
  end

  private
  def method_1(param1, param2)
    return "test"
  end
end

controller tests

describe "GET index" do
  it "get books" do
    param1, param2 = "12334", "456233"
    controller.stub!(:method_1).with(param1,param2).and_return("test")
    get :index
    assert_response :success
    assigns(:test).should eq("test")
  end
end

How to stub a controller private method which will take any arguments

-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list