Some functionality in my app works differently depending on the client’s IP address. Is there a way to test that in Rails functional tests? I’m using Test::Unit and Shoulda.
Some functionality in my app works differently depending on the client’s IP address. Is
Share
You can do this easily without stubbing, by changing the REMOTE_ADDR environment variable before your controller call. Here’s a fictional controller that redirects the user to the home path if their ip address is 1.2.3.4:
Here’s how you can test that it works:
You’re setting the remote ip in advance of the controller call, so you’re able to fake that data without any special plugins or gems. And here’s the shoulda version, for ItemsController: