I am trying to stub a helper method from my helper:
# sessions_helper.rb
require 'rest_client'
module SessionsHelper
BASE_URL = "http://localhost:1234"
def current_user?(token)
sessions_url = BASE_URL + "/sessions"
headers = {"X-AuthToken" => 12345}
begin
RestClient.get(sessions_url, headers)
return true
rescue RestClient::BadRequest
return false
end
end
end
I try to stub the current_user? to always return true in my unit test:
require 'spec_helper'
describe SessionsHelper do
it "Should not get current user with random token" do
SessionsHelper.stub(:current_user?).and_return(true)
expect(current_user?(12345)).to eq(false)
end
end
But the test still pass (I expect it returns true instead).
Is there something I miss to configure the stub method?
Thanks