spec/session_cache.rb in spidr-0.5.0 vs spec/session_cache.rb in spidr-0.6.0

- old
+ new

@@ -1,11 +1,112 @@ require 'spidr/session_cache' require 'spec_helper' +require 'settings/proxy_examples' +require 'settings/timeouts_examples' describe SessionCache do - describe "empty" do + describe "#initialize" do + let(:proxy_host) { 'proxy.example.com' } + let(:proxy_port) { 9999 } + + let(:open_timeout) { 1 } + let(:ssl_timeout) { 2 } + let(:read_timeout) { 3 } + let(:continue_timeout) { 4 } + let(:keep_alive_timeout) { 5 } + + subject do + described_class.new( + proxy: {host: proxy_host, port: proxy_port}, + + open_timeout: open_timeout, + ssl_timeout: ssl_timeout, + read_timeout: read_timeout, + continue_timeout: continue_timeout, + keep_alive_timeout: keep_alive_timeout, + ) + end + + it "should set proxy" do + expect(subject.proxy[:host]).to be == proxy_host + expect(subject.proxy[:port]).to be == proxy_port + end + + it "should set open_timeout" do + expect(subject.open_timeout).to be open_timeout + end + + it "should set ssl_timeout" do + expect(subject.ssl_timeout).to be ssl_timeout + end + + it "should set read_timeout" do + expect(subject.read_timeout).to be read_timeout + end + + it "should set continue_timeout" do + expect(subject.continue_timeout).to be continue_timeout + end + + it "should set keep_alive_timeout" do + expect(subject.keep_alive_timeout).to be keep_alive_timeout + end + + context "with no arguments" do + before(:all) do + Spidr.proxy = {host: 'proxy.example.com', port: 9999} + + Spidr.open_timeout = 1 + Spidr.ssl_timeout = 2 + Spidr.read_timeout = 3 + Spidr.continue_timeout = 4 + Spidr.keep_alive_timeout = 5 + end + + subject { described_class.new } + + it "should use the global proxy settings" do + expect(subject.proxy).to be Spidr.proxy + end + + it "should use the global open_timeout" do + expect(subject.open_timeout).to be == Spidr.open_timeout + end + + it "should use the global ssl_timeout" do + expect(subject.ssl_timeout).to be == Spidr.ssl_timeout + end + + it "should use the global read_timeout" do + expect(subject.read_timeout).to be == Spidr.read_timeout + end + + it "should use the global continue_timeout" do + expect(subject.continue_timeout).to be == Spidr.continue_timeout + end + + it "should use the global keep_alive_timeout" do + expect(subject.keep_alive_timeout).to be == Spidr.keep_alive_timeout + end + + before(:all) do + Spidr.proxy = nil + + Spidr.open_timeout = nil + Spidr.ssl_timeout = nil + Spidr.read_timeout = nil + Spidr.continue_timeout = nil + Spidr.keep_alive_timeout = nil + end + end + end + + it_should_behave_like "includes Spidr::Settings::Proxy" + it_should_behave_like "includes Spidr::Settings::Timeouts" + + context "when empty" do before(:all) do @sessions = SessionCache.new end it "should not have any active sessions" do @@ -19,10 +120,10 @@ after(:all) do @sessions.clear end end - describe "not-empty" do + context "when not-empty" do before(:all) do @url = URI('http://example.com/') @sessions = SessionCache.new @sessions[@url]