From 6a421943972f0baec899d2bb21e293af88cd69ac Mon Sep 17 00:00:00 2001 From: John Joseph Bachir Date: Mon, 6 Oct 2014 13:35:38 -0400 Subject: [PATCH] integration test for FollowRedirects initial simple test for the purpose of discussing how we might want to go about writing integration tests --- Gemfile | 1 + spec/helper.rb | 1 + spec/integration/follow_redirects_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 spec/integration/follow_redirects_spec.rb diff --git a/Gemfile b/Gemfile index be3d3505..2bf613ff 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ group :test do gem 'cane', '>= 2.2.2', :platforms => [:mri_19, :mri_20, :mri_21] gem 'rspec', '>= 3' gem 'simplecov' + gem 'webmock' end gemspec diff --git a/spec/helper.rb b/spec/helper.rb index d9516696..be06a851 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -17,6 +17,7 @@ def format(result) end require 'rspec' +require 'webmock/rspec' require 'faraday' module EnvCompatibility diff --git a/spec/integration/follow_redirects_spec.rb b/spec/integration/follow_redirects_spec.rb new file mode 100644 index 00000000..3d0f01c9 --- /dev/null +++ b/spec/integration/follow_redirects_spec.rb @@ -0,0 +1,22 @@ +require 'helper' +require 'faraday_middleware/response/follow_redirects' + +describe FaradayMiddleware::FollowRedirects do + it "redirects" do + stub_request(:get, "http://facebook.com").to_return( + :status => 302, + :headers => { "Location" => "http://www.facebook.com/" }) + stub_request(:get, "http://www.facebook.com/").to_return( + :status => 302, + :headers => { "Location" => "https://www.facebook.com/" }) + stub_request(:get, "https://www.facebook.com/") + + connection = Faraday.new do |conn| + conn.use FaradayMiddleware::FollowRedirects + conn.adapter Faraday.default_adapter + end + + response = connection.get "http://facebook.com" + expect(response.env[:url].to_s).to eq("https://www.facebook.com/") + end +end