Created
June 16, 2012 17:15
-
-
Save dschneider/2941985 to your computer and use it in GitHub Desktop.
RSpec - Stub Remote IP Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionDispatch::Request.any_instance.stub(:remote_ip).and_return("192.168.0.1") |
Rspec 3
allow_any_instance_of(ActionDispatch::Request).to receive(:remote_ip).and_return('192.168.0.1')
👍 thanks!
I'm getting uninitialized constant ActionDispatch
A different workaround in rspec:
Rspec.configure do |config|
config.before(:each, type: :controller) do
@request.remote_addr = '127.0.0.1'
end
end
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
1️⃣