mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Make use of RSpec DSL consistent across specs
This commit is contained in:
parent
30d90368f6
commit
350d153873
15 changed files with 46 additions and 47 deletions
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::ConnectionAdapter do
|
RSpec.describe HTTParty::ConnectionAdapter do
|
||||||
describe "initialization" do
|
describe "initialization" do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::CookieHash do
|
RSpec.describe HTTParty::CookieHash do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Error do
|
RSpec.describe HTTParty::Error do
|
||||||
subject { described_class }
|
subject { described_class }
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::HashConversions do
|
RSpec.describe HTTParty::HashConversions do
|
||||||
describe ".to_params" do
|
describe ".to_params" do
|
||||||
it "creates a params string from a hash" do
|
it "creates a params string from a hash" do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Logger::ApacheFormatter do
|
RSpec.describe HTTParty::Logger::ApacheFormatter do
|
||||||
let(:subject) { described_class.new(logger_double, :info) }
|
let(:subject) { described_class.new(logger_double, :info) }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Logger::CurlFormatter do
|
RSpec.describe HTTParty::Logger::CurlFormatter do
|
||||||
describe "#format" do
|
describe "#format" do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Logger do
|
RSpec.describe HTTParty::Logger do
|
||||||
describe ".build" do
|
describe ".build" do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
def setup_digest(response)
|
def setup_digest(response)
|
||||||
|
@ -19,7 +19,7 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
|
|
||||||
context 'Net::HTTPHeader#digest_auth' do
|
context 'Net::HTTPHeader#digest_auth' do
|
||||||
let(:headers) {
|
let(:headers) {
|
||||||
(Class.new do
|
(Class.new do
|
||||||
include Net::HTTPHeader
|
include Net::HTTPHeader
|
||||||
def initialize
|
def initialize
|
||||||
@header = {}
|
@header = {}
|
||||||
|
@ -27,25 +27,25 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
@method = 'GET'
|
@method = 'GET'
|
||||||
end
|
end
|
||||||
end).new
|
end).new
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:response){
|
let(:response){
|
||||||
(Class.new do
|
(Class.new do
|
||||||
include Net::HTTPHeader
|
include Net::HTTPHeader
|
||||||
def initialize
|
def initialize
|
||||||
@header = {}
|
@header = {}
|
||||||
self['WWW-Authenticate'] =
|
self['WWW-Authenticate'] =
|
||||||
'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
||||||
end
|
end
|
||||||
end).new
|
end).new
|
||||||
}
|
}
|
||||||
|
|
||||||
it 'should set the authorization header' do
|
it 'should set the authorization header' do
|
||||||
expect(headers['authorization']).to be_nil
|
expect(headers['authorization']).to be_nil
|
||||||
headers.digest_auth('user','pass', response)
|
headers.digest_auth('user','pass', response)
|
||||||
expect(headers['authorization']).to_not be_empty
|
expect(headers['authorization']).to_not be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a cookie value in the response header" do
|
context "with a cookie value in the response header" do
|
||||||
before do
|
before do
|
||||||
|
@ -228,18 +228,18 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
expect(authorization_header).to include(%(response="#{request_digest}"))
|
expect(authorization_header).to include(%(response="#{request_digest}"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with algorithm specified" do
|
context "with algorithm specified" do
|
||||||
before do
|
before do
|
||||||
@digest = setup_digest({
|
@digest = setup_digest({
|
||||||
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5'
|
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should recognise algorithm was specified" do
|
it "should recognise algorithm was specified" do
|
||||||
expect( @digest.send :algorithm_present? ).to be(true)
|
expect( @digest.send :algorithm_present? ).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set the algorithm header" do
|
it "should set the algorithm header" do
|
||||||
expect(authorization_header).to include('algorithm="MD5"')
|
expect(authorization_header).to include('algorithm="MD5"')
|
||||||
end
|
end
|
||||||
|
@ -251,20 +251,20 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5-sess'
|
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth", algorithm=MD5-sess'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should recognise algorithm was specified" do
|
it "should recognise algorithm was specified" do
|
||||||
expect( @digest.send :algorithm_present? ).to be(true)
|
expect( @digest.send :algorithm_present? ).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set the algorithm header" do
|
it "should set the algorithm header" do
|
||||||
expect(authorization_header).to include('algorithm="MD5-sess"')
|
expect(authorization_header).to include('algorithm="MD5-sess"')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set response using md5-sess algorithm" do
|
it "should set response using md5-sess algorithm" do
|
||||||
request_digest = "md5(md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:md5(deadbeef)):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
|
request_digest = "md5(md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:md5(deadbeef)):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
|
||||||
expect(authorization_header).to include(%(response="#{request_digest}"))
|
expect(authorization_header).to include(%(response="#{request_digest}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Parser do
|
RSpec.describe HTTParty::Parser do
|
||||||
describe ".SupportedFormats" do
|
describe ".SupportedFormats" do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
require 'spec_helper'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
|
||||||
describe HTTParty::Request::Body do
|
RSpec.describe HTTParty::Request::Body do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
subject { described_class.new(params).call }
|
subject { described_class.new(params).call }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Request do
|
RSpec.describe HTTParty::Request do
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Response do
|
RSpec.describe HTTParty::Response do
|
||||||
before do
|
before do
|
||||||
|
@ -78,11 +78,11 @@ RSpec.describe HTTParty::Response do
|
||||||
}.to raise_error(NameError, /HTTParty\:\:Response/)
|
}.to raise_error(NameError, /HTTParty\:\:Response/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does raise an error about itself when invoking a method that does not exist' do
|
it 'does raise an error about itself when invoking a method that does not exist' do
|
||||||
expect {
|
expect {
|
||||||
HTTParty::Response.new(@request_object, @response_object, @parsed_response).qux
|
HTTParty::Response.new(@request_object, @response_object, @parsed_response).qux
|
||||||
}.to raise_error(NoMethodError, /HTTParty\:\:Response/)
|
}.to raise_error(NoMethodError, /HTTParty\:\:Response/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns response headers" do
|
it "returns response headers" do
|
||||||
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
|
||||||
|
@ -131,21 +131,21 @@ RSpec.describe HTTParty::Response do
|
||||||
|
|
||||||
context 'response is array' do
|
context 'response is array' do
|
||||||
let(:response_value) { [{'foo' => 'bar'}, {'foo' => 'baz'}] }
|
let(:response_value) { [{'foo' => 'bar'}, {'foo' => 'baz'}] }
|
||||||
let(:response) { HTTParty::Response.new(@request_object, @response_object, lambda { response_value }) }
|
let(:response) { HTTParty::Response.new(@request_object, @response_object, lambda { response_value }) }
|
||||||
it "should be able to iterate" do
|
it "should be able to iterate" do
|
||||||
expect(response.size).to eq(2)
|
expect(response.size).to eq(2)
|
||||||
expect {
|
expect {
|
||||||
response.each { |item| }
|
response.each { |item| }
|
||||||
}.to_not raise_error
|
}.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should respond to array methods' do
|
it 'should respond to array methods' do
|
||||||
expect(response).to respond_to(:bsearch, :compact, :cycle, :delete, :each, :flatten, :flatten!, :compact, :join)
|
expect(response).to respond_to(:bsearch, :compact, :cycle, :delete, :each, :flatten, :flatten!, :compact, :join)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should equal the string response object body' do
|
it 'should equal the string response object body' do
|
||||||
expect(response.to_s).to eq(@response_object.body.to_s)
|
expect(response.to_s).to eq(@response_object.body.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should display the same as an array' do
|
it 'should display the same as an array' do
|
||||||
a = StringIO.new
|
a = StringIO.new
|
||||||
|
@ -153,7 +153,7 @@ RSpec.describe HTTParty::Response do
|
||||||
response_value.display(b)
|
response_value.display(b)
|
||||||
response.display(a)
|
response.display(a)
|
||||||
|
|
||||||
expect(a.string).to eq(b.string)
|
expect(a.string).to eq(b.string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -294,27 +294,27 @@ RSpec.describe HTTParty::Response do
|
||||||
|
|
||||||
describe "headers" do
|
describe "headers" do
|
||||||
let (:empty_headers) { HTTParty::Response::Headers.new }
|
let (:empty_headers) { HTTParty::Response::Headers.new }
|
||||||
let (:some_headers_hash) do
|
let (:some_headers_hash) do
|
||||||
{'Cookie' => 'bob',
|
{'Cookie' => 'bob',
|
||||||
'Content-Encoding' => 'meow'}
|
'Content-Encoding' => 'meow'}
|
||||||
end
|
end
|
||||||
let (:some_headers) do
|
let (:some_headers) do
|
||||||
HTTParty::Response::Headers.new.tap do |h|
|
HTTParty::Response::Headers.new.tap do |h|
|
||||||
some_headers_hash.each_pair do |k,v|
|
some_headers_hash.each_pair do |k,v|
|
||||||
h[k] = v
|
h[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it "can initialize without headers" do
|
it "can initialize without headers" do
|
||||||
expect(empty_headers).to eq({})
|
expect(empty_headers).to eq({})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'always equals itself' do
|
it 'always equals itself' do
|
||||||
expect(empty_headers).to eq(empty_headers)
|
expect(empty_headers).to eq(empty_headers)
|
||||||
expect(some_headers).to eq(some_headers)
|
expect(some_headers).to eq(some_headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not equal itself when not equivalent' do
|
it 'does not equal itself when not equivalent' do
|
||||||
expect(empty_headers).to_not eq(some_headers)
|
expect(empty_headers).to_not eq(some_headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe HTTParty::Request do
|
RSpec.describe HTTParty::Request do
|
||||||
context "SSL certificate verification" do
|
context "SSL certificate verification" do
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
RSpec.describe HTTParty do
|
||||||
|
|
||||||
describe HTTParty do
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@klass = Class.new
|
@klass = Class.new
|
||||||
@klass.instance_eval { include HTTParty }
|
@klass.instance_eval { include HTTParty }
|
||||||
|
|
|
@ -38,8 +38,6 @@ RSpec.configure do |config|
|
||||||
config.order = :random
|
config.order = :random
|
||||||
|
|
||||||
Kernel.srand config.seed
|
Kernel.srand config.seed
|
||||||
|
|
||||||
config.expose_dsl_globally = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec::Matchers.define :use_ssl do
|
RSpec::Matchers.define :use_ssl do
|
||||||
|
|
Loading…
Reference in a new issue