My app is using OpenURI’s open() method, to fetch a web page.
In my spec I want to be able to replace the URL passed in open to the path of a local file.
So when calling open('http://www.google.com') I want to switch that url to /path/to/file.
Is there a build-in way to do this in RSpec?
I do not think rspec provide anything to achieve this. You’re better off adding a parameter to the method that invokes
open()in your application. This will make the code reusable.If the application code cannot be modified, you could try to overwrite the
open()method to substitute the parameter in your rspec script.