Skip to content

Instantly share code, notes, and snippets.

@dschneider
Created June 16, 2012 17:15
Show Gist options
  • Save dschneider/2941985 to your computer and use it in GitHub Desktop.
Save dschneider/2941985 to your computer and use it in GitHub Desktop.
RSpec - Stub Remote IP Request
ActionDispatch::Request.any_instance.stub(:remote_ip).and_return("192.168.0.1")
@spacemunkay
Copy link

spacemunkay commented Mar 20, 2019

A different workaround in rspec:

Rspec.configure do |config|
  config.before(:each, type: :controller) do
    @request.remote_addr = '127.0.0.1'
  end
end

@pjmartorell
Copy link

You should specify if you are talking about controller specs or requests specs, because every kind of test requires a different workaround. In this case I guess you are referring to controller tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment