Mocking request.remote_ip for testing


I'm writing test for some geo-location methods which are all very IP


Is there a good way to mock a request.remote_ip?

Thanks for any help,

Clem C

Have you looked at passing in request parameters to the get method?

get(url, {}, {‘REMOTE_ADDR’=>‘’})

On Sep 17, 3:03 pm, Clem R. [email protected]

I found two solutions that worked nicely for me

  1. @request.stubs(:remote_ip).returns(“”) #using Mocha

  2. def setup
    @controller =
    @request =
    @response =

    @request.instance_eval do
      def remote_ip


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs