spec/faraday_spec.rb in ey-hmac-1.0.0 vs spec/faraday_spec.rb in ey-hmac-2.0.0
- old
+ new
@@ -16,23 +16,23 @@
r.headers = {"Content-Type" => "application/xml"}
end.to_env(Faraday::Connection.new("http://localhost"))
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request[:request_headers]['Authorization'].should start_with("EyHmac")
- request[:request_headers]['Content-Digest'].should == Digest::MD5.hexdigest(request[:body])
- Time.parse(request[:request_headers]['Date']).should_not be_nil
+ expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
+ expect(request[:request_headers]['Content-Digest']).to eq(Digest::MD5.hexdigest(request[:body]))
+ expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
it "should not set Content-Digest if body is nil" do
request = Faraday::Request.new.tap do |r|
r.method = :get
@@ -41,23 +41,23 @@
r.headers = {"Content-Type" => "application/xml"}
end.to_env(Faraday::Connection.new("http://localhost"))
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request[:request_headers]['Authorization'].should start_with("EyHmac")
- request[:request_headers].should_not have_key('Content-Digest')
- Time.parse(request[:request_headers]['Date']).should_not be_nil
+ expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
+ expect(request[:request_headers]).not_to have_key('Content-Digest')
+ expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
it "should not set Content-Digest if body is empty" do
request = Faraday::Request.new.tap do |r|
r.method = :get
@@ -66,23 +66,23 @@
r.headers = {"Content-Type" => "application/xml"}
end.to_env(Faraday::Connection.new("http://localhost"))
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request[:request_headers]['Authorization'].should start_with("EyHmac")
- request[:request_headers].should_not have_key('Content-Digest')
- Time.parse(request[:request_headers]['Date']).should_not be_nil
+ expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
+ expect(request[:request_headers]).not_to have_key('Content-Digest')
+ expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
context "with a request" do
let!(:request) do
Faraday::Request.new.tap do |r|
@@ -106,17 +106,16 @@
(auth_id == key_id) && key_secret
end
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
end
- request_env = nil
connection = Faraday.new do |c|
- c.request :hmac, key_id, key_secret, sign_with: :sha1
+ c.use :hmac, key_id, key_secret, sign_with: :sha1
c.adapter(:rack, app)
end
- connection.get("/resources").status.should == 200
+ expect(connection.get("/resources").status).to eq(200)
end
it "should accept a SHA256 signature" do # default
require 'ey-hmac/faraday'
Bundler.require(:rack)
@@ -126,17 +125,16 @@
(auth_id == key_id) && key_secret
end
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
end
- request_env = nil
connection = Faraday.new do |c|
- c.request :hmac, key_id, key_secret
+ c.use :hmac, key_id, key_secret
c.adapter(:rack, app)
end
- connection.get("/resources").status.should == 200
+ expect(connection.get("/resources").status).to eq(200)
end
it "should accept multiple digest signatures" do # default
require 'ey-hmac/faraday'
Bundler.require(:rack)
@@ -146,17 +144,16 @@
(auth_id == key_id) && key_secret
end
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
end
- request_env = nil
connection = Faraday.new do |c|
- c.request :hmac, key_id, key_secret
+ c.use :hmac, key_id, key_secret
c.adapter(:rack, app)
end
- connection.get("/resources").status.should == 200
+ expect(connection.get("/resources").status).to eq(200)
end
it "should sign empty request" do
require 'ey-hmac/faraday'
Bundler.require(:rack)
@@ -172,20 +169,19 @@
end
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
})
end
- request_env = nil
connection = Faraday.new do |c|
- c.request :hmac, key_id, key_secret
+ c.use :hmac, key_id, key_secret
c.adapter(:rack, app)
end
- connection.get do |req|
+ expect(connection.get do |req|
req.path = "/resource"
req.body = nil
req.params = {"a" => "1"}
req.headers = {"Content-Type" => "application/x-www-form-urlencoded"}
- end.status.should == 200
+ end.status).to eq(200)
end
end
end