Skip to content

Commit

Permalink
Make use of RSpec DSL consistent across specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Herr committed Aug 27, 2018
1 parent 30d9036 commit 49552d9
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 55 deletions.
4 changes: 2 additions & 2 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::ConnectionAdapter do
describe HTTParty::ConnectionAdapter do
describe "initialization" do
let(:uri) { URI 'http://www.google.com' }
it "takes a URI as input" do
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/cookie_hash_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::CookieHash do
describe HTTParty::CookieHash do
before(:each) do
@cookie_hash = HTTParty::CookieHash.new
end
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/exception_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Error do
describe HTTParty::Error do
subject { described_class }

describe '#ancestors' do
Expand Down
4 changes: 3 additions & 1 deletion spec/httparty/hash_conversions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe HTTParty::HashConversions do
require 'spec_helper'

describe HTTParty::HashConversions do
describe ".to_params" do
it "creates a params string from a hash" do
hash = {
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/logger/apache_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Logger::ApacheFormatter do
describe HTTParty::Logger::ApacheFormatter do
let(:subject) { described_class.new(logger_double, :info) }
let(:logger_double) { double('Logger') }
let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "http://my.domain.com/my_path") }
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/logger/curl_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Logger::CurlFormatter do
describe HTTParty::Logger::CurlFormatter do
describe "#format" do
let(:logger) { double('Logger') }
let(:response_object) { Net::HTTPOK.new('1.1', 200, 'OK') }
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/logger/logger_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Logger do
describe HTTParty::Logger do
describe ".build" do
subject { HTTParty::Logger }

Expand Down
34 changes: 17 additions & 17 deletions spec/httparty/net_digest_auth_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe Net::HTTPHeader::DigestAuthenticator do
describe Net::HTTPHeader::DigestAuthenticator do
def setup_digest(response)
digest = Net::HTTPHeader::DigestAuthenticator.new("Mufasa",
"Circle Of Life", "GET", "/dir/index.html", response)
Expand All @@ -19,33 +19,33 @@ def cookie_header

context 'Net::HTTPHeader#digest_auth' do
let(:headers) {
(Class.new do
(Class.new do
include Net::HTTPHeader
def initialize
@header = {}
@path = '/'
@method = 'GET'
end
end).new
}
}

let(:response){
(Class.new do
(Class.new do
include Net::HTTPHeader
def initialize
@header = {}
self['WWW-Authenticate'] =
self['WWW-Authenticate'] =
'Digest realm="[email protected]", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'
end
end).new
}

it 'should set the authorization header' do
it 'should set the authorization header' do
expect(headers['authorization']).to be_nil
headers.digest_auth('user','pass', response)
expect(headers['authorization']).to_not be_empty
end
end
end
end

context "with a cookie value in the response header" do
before do
Expand Down Expand Up @@ -228,18 +228,18 @@ def initialize
expect(authorization_header).to include(%(response="#{request_digest}"))
end
end

context "with algorithm specified" do
before do
@digest = setup_digest({
'www-authenticate' => 'Digest realm="[email protected]", nonce="NONCE", qop="auth", algorithm=MD5'
})
end

it "should recognise algorithm was specified" do
expect( @digest.send :algorithm_present? ).to be(true)
end

it "should set the algorithm header" do
expect(authorization_header).to include('algorithm="MD5"')
end
Expand All @@ -251,20 +251,20 @@ def initialize
'www-authenticate' => 'Digest realm="[email protected]", nonce="NONCE", qop="auth", algorithm=MD5-sess'
})
end

it "should recognise algorithm was specified" do
expect( @digest.send :algorithm_present? ).to be(true)
end

it "should set the algorithm header" do
expect(authorization_header).to include('algorithm="MD5-sess"')
end

it "should set response using md5-sess algorithm" do
request_digest = "md5(md5(md5(Mufasa:[email protected]:Circle Of Life):NONCE:md5(deadbeef)):NONCE:00000001:md5(deadbeef):auth:md5(GET:/dir/index.html))"
expect(authorization_header).to include(%(response="#{request_digest}"))
end

end

end
4 changes: 2 additions & 2 deletions spec/httparty/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Parser do
describe HTTParty::Parser do
describe ".SupportedFormats" do
it "returns a hash" do
expect(HTTParty::Parser::SupportedFormats).to be_instance_of(Hash)
Expand Down
1 change: 1 addition & 0 deletions spec/httparty/request/body_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'spec_helper'
require 'tempfile'

describe HTTParty::Request::Body do
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Request do
describe HTTParty::Request do
before do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml)
end
Expand Down
34 changes: 17 additions & 17 deletions spec/httparty/response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Response do
describe HTTParty::Response do
before do
@last_modified = Date.new(2010, 1, 15).to_s
@content_length = '1024'
Expand Down Expand Up @@ -78,11 +78,11 @@
}.to raise_error(NameError, /HTTParty\:\:Response/)
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 {
HTTParty::Response.new(@request_object, @response_object, @parsed_response).qux
}.to raise_error(NoMethodError, /HTTParty\:\:Response/)
end
end

it "returns response headers" do
response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
Expand Down Expand Up @@ -131,29 +131,29 @@

context 'response is array' do
let(:response_value) { [{'foo' => 'bar'}, {'foo' => 'baz'}] }
let(:response) { HTTParty::Response.new(@request_object, @response_object, lambda { response_value }) }
it "should be able to iterate" do
let(:response) { HTTParty::Response.new(@request_object, @response_object, lambda { response_value }) }
it "should be able to iterate" do
expect(response.size).to eq(2)
expect {
response.each { |item| }
}.to_not raise_error
end

it 'should respond to array methods' do
expect(response).to respond_to(:bsearch, :compact, :cycle, :delete, :each, :flatten, :flatten!, :compact, :join)
it 'should respond to array methods' do
expect(response).to respond_to(:bsearch, :compact, :cycle, :delete, :each, :flatten, :flatten!, :compact, :join)
end

it 'should equal the string response object body' do
expect(response.to_s).to eq(@response_object.body.to_s)
end
expect(response.to_s).to eq(@response_object.body.to_s)
end

it 'should display the same as an array' do
a = StringIO.new
b = StringIO.new
response_value.display(b)
response.display(a)

expect(a.string).to eq(b.string)
expect(a.string).to eq(b.string)
end
end

Expand Down Expand Up @@ -294,27 +294,27 @@ def response_mock(klass)

describe "headers" do
let (:empty_headers) { HTTParty::Response::Headers.new }
let (:some_headers_hash) do
let (:some_headers_hash) do
{'Cookie' => 'bob',
'Content-Encoding' => 'meow'}
end
let (:some_headers) do
end
let (:some_headers) do
HTTParty::Response::Headers.new.tap do |h|
some_headers_hash.each_pair do |k,v|
h[k] = v
end
end
end
it "can initialize without headers" do
it "can initialize without headers" do
expect(empty_headers).to eq({})
end

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)
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)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/ssl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require 'spec_helper'

RSpec.describe HTTParty::Request do
describe HTTParty::Request do
context "SSL certificate verification" do
before do
WebMock.allow_net_connect!
Expand Down
2 changes: 0 additions & 2 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe HTTParty do
before(:each) do
@klass = Class.new
Expand Down

0 comments on commit 49552d9

Please sign in to comment.