@@ -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
145145end
0 commit comments