- # Set things up for OpenID testing
- def openid_setup
- Net::HTTP.get_response(URI.parse("http://localhost:1123/"))
- rescue
- # It isn't, so start a new instance.
- rots = IO.popen("#{Rails.root}/vendor/gems/rots-0.2.1/bin/rots --silent")
-
- # Wait for up to 30 seconds for the server to start and respond before continuing
- 1.upto(30).each do
- begin
- sleep 1
- Net::HTTP.get_response(URI.parse("http://localhost:1123/"))
- # If the rescue block doesn't fire, ROTS is up and running and we can continue
- break
- rescue
- # If the connection failed, do nothing and repeat the loop
- next
+ ##
+ # execute a block with a given set of HTTP responses stubbed
+ def with_http_stubs(stubs_file)
+ http_client_save = OSM.http_client
+
+ begin
+ stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__))
+
+ OSM.http_client = Faraday.new do |builder|
+ builder.adapter :test do |stub|
+ stubs.each do |url, response|
+ stub.get(url) { |_env| [response["code"], {}, response["body"]] }
+ end
+ end