Skip to content

Commit 4971d1a

Browse files
committed
Convert specs to RSpec 2.99.2 syntax with Transpec
This conversion is done by Transpec 3.2.2 with the following command: transpec * 317 conversions from: obj.should to: expect(obj).to * 160 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) * 100 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 30 conversions from: lambda { }.should to: expect { }.to * 22 conversions from: obj.should_not_receive(:message) to: expect(obj).not_to receive(:message) * 4 conversions from: obj.should_not to: expect(obj).not_to * 2 conversions from: == expected to: eq(expected) * 1 conversion from: expect(collection).to have_at_least(n).items to: expect(collection.size).to be >= n * 1 conversion from: obj.unstub(:message) to: allow(obj).to receive(:message).and_call_original For more details: https://github.com/yujinakayama/transpec#supported-conversions
1 parent 718c5ff commit 4971d1a

15 files changed

+695
-695
lines changed

spec/integration/httpbin_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,31 @@ def execute_httpbin_json(suffix, opts={})
4141
describe '.execute' do
4242
it 'sends a user agent' do
4343
data = execute_httpbin_json('user-agent', method: :get)
44-
data['user-agent'].should match(/rest-client/)
44+
expect(data['user-agent']).to match(/rest-client/)
4545
end
4646

4747
it 'receives cookies on 302' do
4848
expect {
4949
execute_httpbin('cookies/set?foo=bar', method: :get, max_redirects: 0)
5050
}.to raise_error(RestClient::Found) { |ex|
51-
ex.http_code.should eq 302
52-
ex.response.cookies['foo'].should eq 'bar'
51+
expect(ex.http_code).to eq 302
52+
expect(ex.response.cookies['foo']).to eq 'bar'
5353
}
5454
end
5555

5656
it 'passes along cookies through 302' do
5757
data = execute_httpbin_json('cookies/set?foo=bar', method: :get)
58-
data.should have_key('cookies')
59-
data['cookies']['foo'].should eq 'bar'
58+
expect(data).to have_key('cookies')
59+
expect(data['cookies']['foo']).to eq 'bar'
6060
end
6161

6262
it 'handles quote wrapped cookies' do
6363
expect {
6464
execute_httpbin('cookies/set?foo=' + CGI.escape('"bar:baz"'),
6565
method: :get, max_redirects: 0)
6666
}.to raise_error(RestClient::Found) { |ex|
67-
ex.http_code.should eq 302
68-
ex.response.cookies['foo'].should eq '"bar:baz"'
67+
expect(ex.http_code).to eq 302
68+
expect(ex.response.cookies['foo']).to eq '"bar:baz"'
6969
}
7070
end
7171
end

spec/integration/integration_spec.rb

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
body = 'abc'
99
stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
1010
response = RestClient.get "www.example.com"
11-
response.code.should eq 200
12-
response.body.should eq body
11+
expect(response.code).to eq 200
12+
expect(response.body).to eq body
1313
end
1414

1515
it "a simple request with gzipped content" do
1616
stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200, :headers => { 'Content-Encoding' => 'gzip' } )
1717
response = RestClient.get "www.example.com"
18-
response.code.should eq 200
19-
response.body.should eq "i'm gziped\n"
18+
expect(response.code).to eq 200
19+
expect(response.body).to eq "i'm gziped\n"
2020
end
2121

2222
it "a 404" do
@@ -26,10 +26,10 @@
2626
RestClient.get "www.example.com"
2727
raise
2828
rescue RestClient::ResourceNotFound => e
29-
e.http_code.should eq 404
30-
e.response.code.should eq 404
31-
e.response.body.should eq body
32-
e.http_body.should eq body
29+
expect(e.http_code).to eq 404
30+
expect(e.response.code).to eq 404
31+
expect(e.response.body).to eq body
32+
expect(e.http_body).to eq body
3333
end
3434
end
3535

@@ -41,8 +41,8 @@
4141
'Content-Type' => 'text/plain; charset=UTF-8'
4242
})
4343
response = RestClient.get "www.example.com"
44-
response.encoding.should eq Encoding::UTF_8
45-
response.valid_encoding?.should eq true
44+
expect(response.encoding).to eq Encoding::UTF_8
45+
expect(response.valid_encoding?).to eq true
4646
end
4747

4848
it 'handles windows-1252' do
@@ -52,9 +52,9 @@
5252
'Content-Type' => 'text/plain; charset=windows-1252'
5353
})
5454
response = RestClient.get "www.example.com"
55-
response.encoding.should eq Encoding::WINDOWS_1252
56-
response.encode('utf-8').should eq "ÿ"
57-
response.valid_encoding?.should eq true
55+
expect(response.encoding).to eq Encoding::WINDOWS_1252
56+
expect(response.encode('utf-8')).to eq "ÿ"
57+
expect(response.valid_encoding?).to eq true
5858
end
5959

6060
it 'handles binary' do
@@ -64,28 +64,28 @@
6464
'Content-Type' => 'application/octet-stream; charset=binary'
6565
})
6666
response = RestClient.get "www.example.com"
67-
response.encoding.should eq Encoding::BINARY
68-
lambda {
67+
expect(response.encoding).to eq Encoding::BINARY
68+
expect {
6969
response.encode('utf-8')
70-
}.should raise_error(Encoding::UndefinedConversionError)
71-
response.valid_encoding?.should eq true
70+
}.to raise_error(Encoding::UndefinedConversionError)
71+
expect(response.valid_encoding?).to eq true
7272
end
7373

7474
it 'handles euc-jp' do
7575
body = "\xA4\xA2\xA4\xA4\xA4\xA6\xA4\xA8\xA4\xAA".
7676
force_encoding(Encoding::BINARY)
7777
body_utf8 = 'あいうえお'
78-
body_utf8.encoding.should eq Encoding::UTF_8
78+
expect(body_utf8.encoding).to eq Encoding::UTF_8
7979

8080
stub_request(:get, 'www.example.com').to_return(
8181
:body => body, :status => 200, :headers => {
8282
'Content-Type' => 'text/plain; charset=EUC-JP'
8383
})
8484
response = RestClient.get 'www.example.com'
85-
response.encoding.should eq Encoding::EUC_JP
86-
response.valid_encoding?.should eq true
87-
response.length.should eq 5
88-
response.encode('utf-8').should eq body_utf8
85+
expect(response.encoding).to eq Encoding::EUC_JP
86+
expect(response.valid_encoding?).to eq true
87+
expect(response.length).to eq 5
88+
expect(response.encode('utf-8')).to eq body_utf8
8989
end
9090

9191
it 'defaults to Encoding.default_external' do
@@ -95,7 +95,7 @@
9595
})
9696

9797
response = RestClient.get 'www.example.com'
98-
response.encoding.should eq Encoding.default_external
98+
expect(response.encoding).to eq Encoding.default_external
9999
end
100100

101101
it 'handles invalid encoding' do
@@ -105,7 +105,7 @@
105105
})
106106

107107
response = RestClient.get 'www.example.com'
108-
response.encoding.should eq Encoding.default_external
108+
expect(response.encoding).to eq Encoding.default_external
109109
end
110110

111111
it 'leaves images as binary' do
@@ -117,7 +117,7 @@
117117
})
118118

119119
response = RestClient.get 'www.example.com'
120-
response.encoding.should eq Encoding::BINARY
120+
expect(response.encoding).to eq Encoding::BINARY
121121
end
122122
end
123123
end

spec/integration/request_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
)
7777
expect {request.execute }.to_not raise_error
78-
ran_callback.should eq(true)
78+
expect(ran_callback).to eq(true)
7979
end
8080

8181
it "fails verification when the callback returns false",

spec/unit/abstract_response_spec.rb

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,124 +22,124 @@ def initialize net_http_res, request
2222
end
2323

2424
it "fetches the numeric response code" do
25-
@net_http_res.should_receive(:code).and_return('200')
26-
@response.code.should eq 200
25+
expect(@net_http_res).to receive(:code).and_return('200')
26+
expect(@response.code).to eq 200
2727
end
2828

2929
it "has a nice description" do
30-
@net_http_res.should_receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
31-
@net_http_res.should_receive(:code).and_return('200')
32-
@response.description.should eq "200 OK | application/pdf bytes\n"
30+
expect(@net_http_res).to receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
31+
expect(@net_http_res).to receive(:code).and_return('200')
32+
expect(@response.description).to eq "200 OK | application/pdf bytes\n"
3333
end
3434

3535
describe '.beautify_headers' do
3636
it "beautifies the headers by turning the keys to symbols" do
3737
h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
38-
h.keys.first.should eq :content_type
38+
expect(h.keys.first).to eq :content_type
3939
end
4040

4141
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
4242
h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
43-
h.values.first.should eq 'text/html'
43+
expect(h.values.first).to eq 'text/html'
4444
end
4545

4646
it 'joins multiple header values by comma' do
47-
RestClient::AbstractResponse.beautify_headers(
47+
expect(RestClient::AbstractResponse.beautify_headers(
4848
{'My-Header' => ['one', 'two']}
49-
).should eq({:my_header => 'one, two'})
49+
)).to eq({:my_header => 'one, two'})
5050
end
5151

5252
it 'leaves set-cookie headers as array' do
53-
RestClient::AbstractResponse.beautify_headers(
53+
expect(RestClient::AbstractResponse.beautify_headers(
5454
{'Set-Cookie' => ['cookie1=foo', 'cookie2=bar']}
55-
).should eq({:set_cookie => ['cookie1=foo', 'cookie2=bar']})
55+
)).to eq({:set_cookie => ['cookie1=foo', 'cookie2=bar']})
5656
end
5757
end
5858

5959
it "fetches the headers" do
60-
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
61-
@response.headers.should eq({ :content_type => 'text/html' })
60+
expect(@net_http_res).to receive(:to_hash).and_return('content-type' => [ 'text/html' ])
61+
expect(@response.headers).to eq({ :content_type => 'text/html' })
6262
end
6363

6464
it "extracts cookies from response headers" do
65-
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
66-
@response.cookies.should eq({ 'session_id' => '1' })
65+
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
66+
expect(@response.cookies).to eq({ 'session_id' => '1' })
6767
end
6868

6969
it "extract strange cookies" do
70-
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
71-
@response.headers.should eq({:set_cookie => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']})
72-
@response.cookies.should eq({ 'session_id' => 'ZJ/HQVH6YE+rVkTpn0zvTQ==' })
70+
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
71+
expect(@response.headers).to eq({:set_cookie => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']})
72+
expect(@response.cookies).to eq({ 'session_id' => 'ZJ/HQVH6YE+rVkTpn0zvTQ==' })
7373
end
7474

7575
it "doesn't escape cookies" do
76-
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
77-
@response.cookies.should eq({ 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' })
76+
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
77+
expect(@response.cookies).to eq({ 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' })
7878
end
7979

8080
describe '.cookie_jar' do
8181
it 'extracts cookies into cookie jar' do
82-
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
83-
@response.cookie_jar.should be_a HTTP::CookieJar
82+
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
83+
expect(@response.cookie_jar).to be_a HTTP::CookieJar
8484

8585
cookie = @response.cookie_jar.cookies.first
86-
cookie.domain.should eq 'example.com'
87-
cookie.name.should eq 'session_id'
88-
cookie.value.should eq '1'
89-
cookie.path.should eq '/'
86+
expect(cookie.domain).to eq 'example.com'
87+
expect(cookie.name).to eq 'session_id'
88+
expect(cookie.value).to eq '1'
89+
expect(cookie.path).to eq '/'
9090
end
9191

9292
it 'handles cookies when URI scheme is implicit' do
9393
net_http_res = double('net http response')
94-
net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
94+
expect(net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
9595
request = double(url: 'example.com', uri: URI.parse('http://example.com'),
9696
method: 'get', cookie_jar: HTTP::CookieJar.new)
9797
response = MyAbstractResponse.new(net_http_res, request)
98-
response.cookie_jar.should be_a HTTP::CookieJar
98+
expect(response.cookie_jar).to be_a HTTP::CookieJar
9999

100100
cookie = response.cookie_jar.cookies.first
101-
cookie.domain.should eq 'example.com'
102-
cookie.name.should eq 'session_id'
103-
cookie.value.should eq '1'
104-
cookie.path.should eq '/'
101+
expect(cookie.domain).to eq 'example.com'
102+
expect(cookie.name).to eq 'session_id'
103+
expect(cookie.value).to eq '1'
104+
expect(cookie.path).to eq '/'
105105
end
106106
end
107107

108108
it "can access the net http result directly" do
109-
@response.net_http_res.should eq @net_http_res
109+
expect(@response.net_http_res).to eq @net_http_res
110110
end
111111

112112
describe "#return!" do
113113
it "should return the response itself on 200-codes" do
114-
@net_http_res.should_receive(:code).and_return('200')
115-
@response.return!.should be_equal(@response)
114+
expect(@net_http_res).to receive(:code).and_return('200')
115+
expect(@response.return!).to be_equal(@response)
116116
end
117117

118118
it "should raise RequestFailed on unknown codes" do
119-
@net_http_res.should_receive(:code).and_return('1000')
120-
lambda { @response.return! }.should raise_error RestClient::RequestFailed
119+
expect(@net_http_res).to receive(:code).and_return('1000')
120+
expect { @response.return! }.to raise_error RestClient::RequestFailed
121121
end
122122

123123
it "should raise an error on a redirection after non-GET/HEAD requests" do
124-
@net_http_res.should_receive(:code).and_return('301')
125-
@request.should_receive(:method).and_return('put')
126-
@response.should_not_receive(:follow_redirection)
127-
lambda { @response.return! }.should raise_error RestClient::RequestFailed
124+
expect(@net_http_res).to receive(:code).and_return('301')
125+
expect(@request).to receive(:method).and_return('put')
126+
expect(@response).not_to receive(:follow_redirection)
127+
expect { @response.return! }.to raise_error RestClient::RequestFailed
128128
end
129129

130130
it "should follow 302 redirect" do
131-
@net_http_res.should_receive(:code).and_return('302')
132-
@response.should_receive(:check_max_redirects).and_return('fake-check')
133-
@response.should_receive(:follow_redirection).and_return('fake-redirection')
134-
@response.return!.should eq 'fake-redirection'
131+
expect(@net_http_res).to receive(:code).and_return('302')
132+
expect(@response).to receive(:check_max_redirects).and_return('fake-check')
133+
expect(@response).to receive(:follow_redirection).and_return('fake-redirection')
134+
expect(@response.return!).to eq 'fake-redirection'
135135
end
136136

137137
it "should gracefully handle 302 redirect with no location header" do
138138
@net_http_res = response_double(code: 302, location: nil)
139139
@request = request_double()
140140
@response = MyAbstractResponse.new(@net_http_res, @request)
141-
@response.should_receive(:check_max_redirects).and_return('fake-check')
142-
lambda { @response.return! }.should raise_error RestClient::Found
141+
expect(@response).to receive(:check_max_redirects).and_return('fake-check')
142+
expect { @response.return! }.to raise_error RestClient::Found
143143
end
144144
end
145145
end

0 commit comments

Comments
 (0)