Permalink
Browse files

Convert specs to the new RSpec expectation syntax

  • Loading branch information...
1 parent feedd2f commit 6179871d42806eb89409af5b2c89e5bb1d9ffa57 @sferik sferik committed Oct 10, 2012
View
@@ -152,4 +152,4 @@ def test_doesnt_cache_post
assert_equal 'request:2', post('/').body
assert_equal 'request:3', post('/').body
end
-end unless defined? RUBY_ENGINE and "rbx" == RUBY_ENGINE # rbx bug #1522
+end unless defined? RUBY_ENGINE and "rbx" == RUBY_ENGINE # rbx bug #1522
View
@@ -4,75 +4,75 @@
describe FaradayMiddleware::Chunked, :type => :response do
context "no transfer-encoding" do
it "doesn't change nil body" do
- process(nil).body.should be_nil
+ expect(process(nil).body).to be_nil
end
it "doesn't change an empty body" do
- process('').body.should eql('')
+ expect(process('').body).to eq('')
end
it "doesn't change a normal body" do
- process('asdf').body.should eql('asdf')
+ expect(process('asdf').body).to eq('asdf')
end
end
context "transfer-encoding gzip" do
let(:headers) { {"transfer-encoding" => "gzip"}}
it "doesn't change nil body" do
- process(nil).body.should be_nil
+ expect(process(nil).body).to be_nil
end
it "doesn't change an empty body" do
- process('').body.should eql('')
+ expect(process('').body).to eq('')
end
it "doesn't change a normal body" do
- process('asdf').body.should eql('asdf')
+ expect(process('asdf').body).to eq('asdf')
end
end
context "transfer-encoding chunked" do
let(:headers) { {"transfer-encoding" => "chunked"}}
it "doesn't change nil body" do
- process(nil).body.should be_nil
+ expect(process(nil).body).to be_nil
end
it "doesn't change an empty body" do
- process('').body.should eql('')
+ expect(process('').body).to eq('')
end
it "parses a basic chunked body" do
- process("10\r\nasdfghjklasdfghj\r\n0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10\r\nasdfghjklasdfghj\r\n0\r\n").body).to eq('asdfghjklasdfghj')
end
it "parses a chunked body with no ending chunk" do
- process("10\r\nasdfghjklasdfghj\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10\r\nasdfghjklasdfghj\r\n").body).to eq('asdfghjklasdfghj')
end
it "parses a chunked body with no trailing CRLF on the data chunk" do
- process("10\r\nasdfghjklasdfghj0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10\r\nasdfghjklasdfghj0\r\n").body).to eq('asdfghjklasdfghj')
end
it "parses a chunked body with an extension" do
- process("10;foo=bar\r\nasdfghjklasdfghj\r\n0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10;foo=bar\r\nasdfghjklasdfghj\r\n0\r\n").body).to eq('asdfghjklasdfghj')
end
it "parses a chunked body with two extensions" do
- process("10;foo=bar;bar=baz\r\nasdfghjklasdfghj\r\n0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10;foo=bar;bar=baz\r\nasdfghjklasdfghj\r\n0\r\n").body).to eq('asdfghjklasdfghj')
end
it "parses a chunked body with two chunks" do
- process("8\r\nasdfghjk\r\n8\r\nlasdfghj\r\n0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("8\r\nasdfghjk\r\n8\r\nlasdfghj\r\n0\r\n").body).to eq('asdfghjklasdfghj')
end
end
context "transfer-encoding chunked,chunked" do
let(:headers) { {"transfer-encoding" => "chunked,chunked"}}
it "parses a basic chunked body" do
- process("10\r\nasdfghjklasdfghj\r\n0\r\n").body.should eql('asdfghjklasdfghj')
+ expect(process("10\r\nasdfghjklasdfghj\r\n0\r\n").body).to eq('asdfghjklasdfghj')
end
end
end
View
@@ -17,79 +17,79 @@ def result_type() result[:request_headers]['content-type'] end
let(:result) { process(nil) }
it "doesn't change body" do
- result_body.should be_nil
+ expect(result_body).to be_nil
end
it "doesn't add content type" do
- result_type.should be_nil
+ expect(result_type).to be_nil
end
end
context "empty body" do
let(:result) { process('') }
it "doesn't change body" do
- result_body.should be_empty
+ expect(result_body).to be_empty
end
it "doesn't add content type" do
- result_type.should be_nil
+ expect(result_type).to be_nil
end
end
context "string body" do
let(:result) { process('{"a":1}') }
it "doesn't change body" do
- result_body.should eql('{"a":1}')
+ expect(result_body).to eq('{"a":1}')
end
it "adds content type" do
- result_type.should eql('application/json')
+ expect(result_type).to eq('application/json')
end
end
context "object body" do
let(:result) { process({:a => 1}) }
it "encodes body" do
- result_body.should eql('{"a":1}')
+ expect(result_body).to eq('{"a":1}')
end
it "adds content type" do
- result_type.should eql('application/json')
+ expect(result_type).to eq('application/json')
end
end
context "empty object body" do
let(:result) { process({}) }
it "encodes body" do
- result_body.should eql('{}')
+ expect(result_body).to eq('{}')
end
end
context "object body with json type" do
let(:result) { process({:a => 1}, 'application/json; charset=utf-8') }
it "encodes body" do
- result_body.should eql('{"a":1}')
+ expect(result_body).to eq('{"a":1}')
end
it "doesn't change content type" do
- result_type.should eql('application/json; charset=utf-8')
+ expect(result_type).to eq('application/json; charset=utf-8')
end
end
context "object body with incompatible type" do
let(:result) { process({:a => 1}, 'application/xml; charset=utf-8') }
it "doesn't change body" do
- result_body.should eql({:a => 1})
+ expect(result_body).to eq({:a => 1})
end
it "doesn't change content type" do
- result_type.should eql('application/xml; charset=utf-8')
+ expect(result_type).to eq('application/xml; charset=utf-8')
end
end
end
@@ -8,41 +8,41 @@
describe FaradayMiddleware::FollowRedirects do
let(:middleware_options) { Hash.new }
- shared_examples_for 'a successful redirection' do |status_code|
+ shared_examples_for "a successful redirection" do |status_code|
it "follows the redirection for a GET request" do
- connection do |stub|
+ expect(connection do |stub|
stub.get('/permanent') { [status_code, {'Location' => '/found'}, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
- end.get('/permanent').body.should eql 'fin'
+ end.get('/permanent').body).to eq 'fin'
end
[:head, :options].each do |method|
it "returning the response headers for a #{method.to_s.upcase} request" do
- connection do |stub|
+ expect(connection do |stub|
stub.new_stub(method, '/permanent') { [status_code, {'Location' => '/found'}, ''] }
- end.run_request(method, '/permanent', nil, nil).headers['Location'].should eql('/found')
+ end.run_request(method, '/permanent', nil, nil).headers['Location']).to eq('/found')
end
end
end
- shared_examples_for 'a forced GET redirection' do |status_code|
+ shared_examples_for "a forced GET redirection" do |status_code|
[:put, :post, :delete, :patch].each do |method|
it "a #{method.to_s.upcase} request is converted to a GET" do
- connection = connection do |stub|
+ expect(connection do |stub|
stub.new_stub(method, '/redirect') {
[status_code, {'Location' => '/found'}, 'elsewhere']
}
stub.get('/found') { |env|
body = env[:body] and body.empty? && (body = nil)
[200, {'Content-Type' => 'text/plain'}, body.inspect]
}
- end.run_request(method, '/redirect', 'request data', nil).body.should eql('nil')
+ end.run_request(method, '/redirect', 'request data', nil).body).to eq('nil')
end
end
end
- shared_examples_for 'a replayed redirection' do |status_code|
- it 'redirects with the original request headers' do
+ shared_examples_for "a replayed redirection" do |status_code|
+ it "redirects with the original request headers" do
conn = connection do |stub|
stub.get('/redirect') {
[status_code, {'Location' => '/found'}, '']
@@ -56,15 +56,15 @@
req.headers['X-Test-Value'] = 'success'
}
- response.body.should eql('success')
+ expect(response.body).to eq('success')
end
[:put, :post, :delete, :patch].each do |method|
it "replays a #{method.to_s.upcase} request" do
- connection do |stub|
+ expect(connection do |stub|
stub.new_stub(method, '/redirect') { [status_code, {'Location' => '/found'}, ''] }
stub.new_stub(method, '/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
- end.run_request(method, '/redirect', nil, nil).body.should eql 'fin'
+ end.run_request(method, '/redirect', nil, nil).body).to eq 'fin'
end
end
@@ -80,32 +80,32 @@
end
response = conn.run_request(method, '/redirect', 'original data', nil)
- response.body.should eql('original data')
+ expect(response.body).to eq('original data')
end
end
end
it "returns non-redirect response results" do
- connection do |stub|
+ expect(connection do |stub|
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
- end.get('/found').body.should eql 'fin'
+ end.get('/found').body).to eq 'fin'
end
it "follows a single redirection" do
- connection do |stub|
+ expect(connection do |stub|
stub.get('/') { [301, {'Location' => '/found'}, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
- end.get('/').body.should eql 'fin'
+ end.get('/').body).to eq 'fin'
end
it "follows many redirections" do
- connection do |stub|
+ expect(connection do |stub|
stub.get('/') { [301, {'Location' => '/redirect1'}, ''] }
stub.get('/redirect1') { [301, {'Location' => '/redirect2'}, ''] }
stub.get('/redirect2') { [301, {'Location' => '/found'}, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
- end.get('/').body.should eql 'fin'
+ end.get('/').body).to eq 'fin'
end
it "raises a FaradayMiddleware::RedirectLimitReached after 3 redirections (by default)" do
@@ -117,7 +117,7 @@
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
end
- expect { conn.get('/') }.to raise_error(FaradayMiddleware::RedirectLimitReached)
+ expect{ conn.get('/') }.to raise_error(FaradayMiddleware::RedirectLimitReached)
end
it "raises a FaradayMiddleware::RedirectLimitReached after the initialized limit" do
@@ -127,65 +127,65 @@
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
end
- expect { conn.get('/') }.to raise_error(FaradayMiddleware::RedirectLimitReached)
+ expect{ conn.get('/') }.to raise_error(FaradayMiddleware::RedirectLimitReached)
end
- context 'when cookies option' do
+ context "when cookies option" do
let(:cookies) { 'cookie1=abcdefg; cookie2=1234567; cookie3=awesome' }
context "is :all" do
it "puts all cookies from the response into the next request" do
- conn = connection(:cookies => :all) do |stub|
+ expect(connection(:cookies => :all) do |stub|
stub.get('/') { [301, {'Location' => '/found', 'Cookies' => cookies }, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, ''] }
- end.get('/').env[:request_headers][:cookies].should == cookies
+ end.get('/').env[:request_headers][:cookies]).to eq(cookies)
end
it "not set cookies header on request when response has no cookies" do
- conn = connection(:cookies => :all) do |stub|
+ expect(connection(:cookies => :all) do |stub|
stub.get('/') { [301, {'Location' => '/found'}, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, ''] }
- end.get('/').env[:request_headers].has_key?('Cookies').should == false
+ end.get('/').env[:request_headers].has_key?('Cookies')).to eq(false)
end
end
context "is an array of cookie names" do
it "puts selected cookies from the response into the next request" do
- conn = connection(:cookies => ['cookie2']) do |stub|
+ expect(connection(:cookies => ['cookie2']) do |stub|
stub.get('/') { [301, {'Location' => '/found', 'Cookies' => cookies }, ''] }
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, ''] }
- end.get('/').env[:request_headers][:cookies].should == 'cookie2=1234567'
+ end.get('/').env[:request_headers][:cookies]).to eq('cookie2=1234567')
end
end
end
- context 'for an HTTP 301 response' do
- it_should_behave_like 'a successful redirection', 301
- it_should_behave_like 'a forced GET redirection', 301
+ context "for an HTTP 301 response" do
+ it_behaves_like 'a successful redirection', 301
+ it_behaves_like 'a forced GET redirection', 301
end
- context 'for an HTTP 302 response' do
- it_should_behave_like 'a successful redirection', 302
+ context "for an HTTP 302 response" do
+ it_behaves_like 'a successful redirection', 302
- context 'by default' do
- it_should_behave_like 'a forced GET redirection', 302
+ context "by default" do
+ it_behaves_like 'a forced GET redirection', 302
end
- context 'with standards compliancy enabled' do
+ context "with standards compliancy enabled" do
let(:middleware_options) { { :standards_compliant => true } }
- it_should_behave_like 'a replayed redirection', 302
+ it_behaves_like 'a replayed redirection', 302
end
end
- context 'for an HTTP 303 response' do
- it_should_behave_like 'a successful redirection', 303
- it_should_behave_like 'a forced GET redirection', 303
+ context "for an HTTP 303 response" do
+ it_behaves_like 'a successful redirection', 303
+ it_behaves_like 'a forced GET redirection', 303
end
- context 'for an HTTP 307 response' do
- it_should_behave_like 'a successful redirection', 307
- it_should_behave_like 'a replayed redirection', 307
+ context "for an HTTP 307 response" do
+ it_behaves_like 'a successful redirection', 307
+ it_behaves_like 'a replayed redirection', 307
end
# checks env hash in request phase for basic validity
Oops, something went wrong.

0 comments on commit 6179871

Please sign in to comment.