Forum: RSpec Stub a controller private method containing arguments

6ad08986261a261beffe99e2f5bf01e3?d=identicon&s=25 jeevan reddy (jeevan_169)
on 2012-09-09 08:00
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 different
arguments
If we pass "123", "456" set, then the test will pass
For ex: method_1 should accept "12334", "456233" arguments
Any help is appreciated.

Thanks in advance
jeevan
This topic is locked and can not be replied to.