summaryrefslogtreecommitdiff
path: root/spec/unit/http
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-10-29 15:14:22 -0700
committerClaire McQuin <claire@getchef.com>2014-10-29 15:59:04 -0700
commit5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch)
tree14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/http
parentb92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff)
downloadchef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz
Update to RSpec 3.
Diffstat (limited to 'spec/unit/http')
-rw-r--r--spec/unit/http/basic_client_spec.rb6
-rw-r--r--spec/unit/http/http_request_spec.rb20
-rw-r--r--spec/unit/http/simple_spec.rb6
-rw-r--r--spec/unit/http/ssl_policies_spec.rb30
-rw-r--r--spec/unit/http/validate_content_length_spec.rb22
5 files changed, 42 insertions, 42 deletions
diff --git a/spec/unit/http/basic_client_spec.rb b/spec/unit/http/basic_client_spec.rb
index cb1f2fd979..eb133f943e 100644
--- a/spec/unit/http/basic_client_spec.rb
+++ b/spec/unit/http/basic_client_spec.rb
@@ -35,7 +35,7 @@ describe "HTTP Connection" do
end
it "should set an open timeout" do
- subject.build_http_client.open_timeout.should_not be_nil
+ expect(subject.build_http_client.open_timeout).not_to be_nil
end
end
@@ -52,12 +52,12 @@ describe "HTTP Connection" do
it "should contain the host" do
proxy_uri = subject.proxy_uri
- proxy_uri.host.should == proxy_host
+ expect(proxy_uri.host).to eq(proxy_host)
end
it "should contain the port" do
proxy_uri = subject.proxy_uri
- proxy_uri.port.should == proxy_port
+ expect(proxy_uri.port).to eq(proxy_port)
end
end
diff --git a/spec/unit/http/http_request_spec.rb b/spec/unit/http/http_request_spec.rb
index d573d4c5dc..3bba201963 100644
--- a/spec/unit/http/http_request_spec.rb
+++ b/spec/unit/http/http_request_spec.rb
@@ -25,31 +25,31 @@ describe Chef::HTTP::HTTPRequest do
it "should not include port 80 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com'), '')
- request.headers['Host'].should eql('dummy.com')
+ expect(request.headers['Host']).to eql('dummy.com')
end
it "should not include explicit port 80 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com:80'), '')
- request.headers['Host'].should eql('dummy.com')
+ expect(request.headers['Host']).to eql('dummy.com')
end
it "should include explicit port 8000 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com:8000'), '')
- request.headers['Host'].should eql('dummy.com:8000')
+ expect(request.headers['Host']).to eql('dummy.com:8000')
end
it "should include explicit 443 port in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com:443'), '')
- request.headers['Host'].should eql('dummy.com:443')
+ expect(request.headers['Host']).to eql('dummy.com:443')
end
it "should pass on explicit Host header unchanged" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com:8000'), '', { 'Host' => 'yourhost.com:8888' })
- request.headers['Host'].should eql('yourhost.com:8888')
+ expect(request.headers['Host']).to eql('yourhost.com:8888')
end
end
@@ -59,25 +59,25 @@ describe Chef::HTTP::HTTPRequest do
it "should not include port 443 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('https://dummy.com'), '')
- request.headers['Host'].should eql('dummy.com')
+ expect(request.headers['Host']).to eql('dummy.com')
end
it "should include explicit port 80 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('https://dummy.com:80'), '')
- request.headers['Host'].should eql('dummy.com:80')
+ expect(request.headers['Host']).to eql('dummy.com:80')
end
it "should include explicit port 8000 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('https://dummy.com:8000'), '')
- request.headers['Host'].should eql('dummy.com:8000')
+ expect(request.headers['Host']).to eql('dummy.com:8000')
end
it "should not include explicit port 443 in Host header" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('https://dummy.com:443'), '')
- request.headers['Host'].should eql('dummy.com')
+ expect(request.headers['Host']).to eql('dummy.com')
end
end
@@ -85,7 +85,7 @@ describe Chef::HTTP::HTTPRequest do
it "should pass on explicit Host header unchanged" do
request = Chef::HTTP::HTTPRequest.new(:GET, URI('http://dummy.com:8000'), '', { 'Host' => 'myhost.com:80' })
- request.headers['Host'].should eql('myhost.com:80')
+ expect(request.headers['Host']).to eql('myhost.com:80')
end
end
diff --git a/spec/unit/http/simple_spec.rb b/spec/unit/http/simple_spec.rb
index b33ef1d553..c8fb52e8b2 100644
--- a/spec/unit/http/simple_spec.rb
+++ b/spec/unit/http/simple_spec.rb
@@ -25,8 +25,8 @@ describe Chef::HTTP::Simple do
content_length = middlewares.find_index { |e| e.is_a? Chef::HTTP::ValidateContentLength }
decompressor = middlewares.find_index { |e| e.is_a? Chef::HTTP::Decompressor }
- content_length.should_not be_nil
- decompressor.should_not be_nil
- (decompressor < content_length).should be_true
+ expect(content_length).not_to be_nil
+ expect(decompressor).not_to be_nil
+ expect(decompressor < content_length).to be_truthy
end
end
diff --git a/spec/unit/http/ssl_policies_spec.rb b/spec/unit/http/ssl_policies_spec.rb
index b95e13a370..5ebebf39b1 100644
--- a/spec/unit/http/ssl_policies_spec.rb
+++ b/spec/unit/http/ssl_policies_spec.rb
@@ -45,31 +45,31 @@ describe "HTTP SSL Policy" do
end
it "configures the HTTP client to use SSL when given a URL with the https protocol" do
- http_client.use_ssl?.should be_true
+ expect(http_client.use_ssl?).to be_truthy
end
it "sets the OpenSSL verify mode to verify_peer" do
- http_client.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
+ expect(http_client.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
end
it "raises a ConfigurationError if :ssl_ca_path is set to a path that doesn't exist" do
Chef::Config[:ssl_ca_path] = "/dev/null/nothing_here"
- lambda {http_client}.should raise_error(Chef::Exceptions::ConfigurationError)
+ expect {http_client}.to raise_error(Chef::Exceptions::ConfigurationError)
end
it "should set the CA path if that is set in the configuration" do
Chef::Config[:ssl_ca_path] = File.join(CHEF_SPEC_DATA, "ssl")
- http_client.ca_path.should == File.join(CHEF_SPEC_DATA, "ssl")
+ expect(http_client.ca_path).to eq(File.join(CHEF_SPEC_DATA, "ssl"))
end
it "raises a ConfigurationError if :ssl_ca_file is set to a file that does not exist" do
Chef::Config[:ssl_ca_file] = "/dev/null/nothing_here"
- lambda {http_client}.should raise_error(Chef::Exceptions::ConfigurationError)
+ expect {http_client}.to raise_error(Chef::Exceptions::ConfigurationError)
end
it "should set the CA file if that is set in the configuration" do
Chef::Config[:ssl_ca_file] = CHEF_SPEC_DATA + '/ssl/5e707473.0'
- http_client.ca_file.should == CHEF_SPEC_DATA + '/ssl/5e707473.0'
+ expect(http_client.ca_file).to eq(CHEF_SPEC_DATA + '/ssl/5e707473.0')
end
end
@@ -80,7 +80,7 @@ describe "HTTP SSL Policy" do
end
it "sets the OpenSSL verify mode to :verify_none" do
- http_client.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
+ expect(http_client.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
end
end
@@ -90,26 +90,26 @@ describe "HTTP SSL Policy" do
it "raises ConfigurationError if the certificate file doesn't exist" do
Chef::Config[:ssl_client_cert] = "/dev/null/nothing_here"
Chef::Config[:ssl_client_key] = CHEF_SPEC_DATA + '/ssl/chef-rspec.key'
- lambda {http_client}.should raise_error(Chef::Exceptions::ConfigurationError)
+ expect {http_client}.to raise_error(Chef::Exceptions::ConfigurationError)
end
it "raises ConfigurationError if the certificate file doesn't exist" do
Chef::Config[:ssl_client_cert] = CHEF_SPEC_DATA + '/ssl/chef-rspec.cert'
Chef::Config[:ssl_client_key] = "/dev/null/nothing_here"
- lambda {http_client}.should raise_error(Chef::Exceptions::ConfigurationError)
+ expect {http_client}.to raise_error(Chef::Exceptions::ConfigurationError)
end
it "raises a ConfigurationError if one of :ssl_client_cert and :ssl_client_key is set but not both" do
Chef::Config[:ssl_client_cert] = "/dev/null/nothing_here"
Chef::Config[:ssl_client_key] = nil
- lambda {http_client}.should raise_error(Chef::Exceptions::ConfigurationError)
+ expect {http_client}.to raise_error(Chef::Exceptions::ConfigurationError)
end
it "configures the HTTP client's cert and private key" do
Chef::Config[:ssl_client_cert] = CHEF_SPEC_DATA + '/ssl/chef-rspec.cert'
Chef::Config[:ssl_client_key] = CHEF_SPEC_DATA + '/ssl/chef-rspec.key'
- http_client.cert.to_s.should == OpenSSL::X509::Certificate.new(IO.read(CHEF_SPEC_DATA + '/ssl/chef-rspec.cert')).to_s
- http_client.key.to_s.should == IO.read(CHEF_SPEC_DATA + '/ssl/chef-rspec.key')
+ expect(http_client.cert.to_s).to eq(OpenSSL::X509::Certificate.new(IO.read(CHEF_SPEC_DATA + '/ssl/chef-rspec.cert')).to_s)
+ expect(http_client.key.to_s).to eq(IO.read(CHEF_SPEC_DATA + '/ssl/chef-rspec.key'))
end
end
@@ -125,7 +125,7 @@ describe "HTTP SSL Policy" do
end
it "enables verification of self-signed certificates" do
- http_client.cert_store.verify(self_signed_crt).should be_true
+ expect(http_client.cert_store.verify(self_signed_crt)).to be_truthy
end
it "enables verification of cert chains" do
@@ -137,7 +137,7 @@ describe "HTTP SSL Policy" do
# If the machine running the test doesn't have ruby SSL configured correctly,
# then the root cert also has to be loaded for the test to succeed.
# The system under test **SHOULD** do both of these things.
- http_client.cert_store.verify(additional_pem).should be_true
+ expect(http_client.cert_store.verify(additional_pem)).to be_truthy
end
context "and some certs are duplicates" do
@@ -161,7 +161,7 @@ describe "HTTP SSL Policy" do
end
it "sets the OpenSSL verify mode to verify_peer" do
- http_client.verify_mode.should == OpenSSL::SSL::VERIFY_PEER
+ expect(http_client.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
end
end
diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb
index 091f2b0757..34b6a61a3a 100644
--- a/spec/unit/http/validate_content_length_spec.rb
+++ b/spec/unit/http/validate_content_length_spec.rb
@@ -45,7 +45,7 @@ describe Chef::HTTP::ValidateContentLength do
let(:response) {
m = double('HttpResponse', :body => response_body)
- m.stub(:[]) do |key|
+ allow(m).to receive(:[]) do |key|
response_headers[key]
end
@@ -85,7 +85,7 @@ describe Chef::HTTP::ValidateContentLength do
before(:each) {
Chef::Log.level = :debug
- Chef::Log.stub(:debug) do |message|
+ allow(Chef::Log).to receive(:debug) do |message|
debug_stream.puts message
end
}
@@ -95,7 +95,7 @@ describe Chef::HTTP::ValidateContentLength do
let(:response_body) { "Thanks for checking in." }
it "shouldn't raise error" do
- lambda { run_content_length_validation }.should_not raise_error
+ expect { run_content_length_validation }.not_to raise_error
end
end
@@ -108,7 +108,7 @@ describe Chef::HTTP::ValidateContentLength do
it "should skip validation and log for debug" do
run_content_length_validation
- debug_output.should include("HTTP server did not include a Content-Length header in response")
+ expect(debug_output).to include("HTTP server did not include a Content-Length header in response")
end
end
end
@@ -121,7 +121,7 @@ describe Chef::HTTP::ValidateContentLength do
it "should validate correctly" do
run_content_length_validation
- debug_output.should include("Content-Length validated correctly.")
+ expect(debug_output).to include("Content-Length validated correctly.")
end
end
end
@@ -134,7 +134,7 @@ describe Chef::HTTP::ValidateContentLength do
let(:request_type) { req_type.to_sym }
it "should raise ContentLengthMismatch error" do
- lambda { run_content_length_validation }.should raise_error(Chef::Exceptions::ContentLengthMismatch)
+ expect { run_content_length_validation }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end
end
end
@@ -144,7 +144,7 @@ describe Chef::HTTP::ValidateContentLength do
let(:streaming_length) { 12 }
it "should raise ContentLengthMismatch error" do
- lambda { run_content_length_validation }.should raise_error(Chef::Exceptions::ContentLengthMismatch)
+ expect { run_content_length_validation }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end
end
@@ -162,7 +162,7 @@ describe Chef::HTTP::ValidateContentLength do
it "should skip validation and log for debug" do
run_content_length_validation
- debug_output.should include("Transfer-Encoding header is set, skipping Content-Length check.")
+ expect(debug_output).to include("Transfer-Encoding header is set, skipping Content-Length check.")
end
end
end
@@ -171,16 +171,16 @@ describe Chef::HTTP::ValidateContentLength do
describe "when client is being reused" do
before do
run_content_length_validation
- debug_output.should include("Content-Length validated correctly.")
+ expect(debug_output).to include("Content-Length validated correctly.")
end
it "should reset internal counter" do
- middleware.instance_variable_get(:@content_length_counter).should be_nil
+ expect(middleware.instance_variable_get(:@content_length_counter)).to be_nil
end
it "should validate correctly second time" do
run_content_length_validation
- debug_output.should include("Content-Length validated correctly.")
+ expect(debug_output).to include("Content-Length validated correctly.")
end
end