@@ -65,14 +65,8 @@ module VCR
6565 include_context "configuration stubbing"
6666 before { allow ( config ) . to receive ( :uri_parser ) { LimitedURI } }
6767
68- if '' . respond_to? ( :encoding )
69- def body_hash ( key , value )
70- { key => value , 'encoding' => 'UTF-8' }
71- end
72- else
73- def body_hash ( key , value )
74- { key => value }
75- end
68+ def body_hash ( key , value )
69+ { key => value , 'encoding' => 'UTF-8' }
7670 end
7771
7872 describe "#recorded_at" do
@@ -164,95 +158,93 @@ def body_hash(key, value)
164158 expect ( i . response . body ) . to eq ( 'res body' )
165159 end
166160
167- if '' . respond_to? ( :encoding )
168- it 'force encodes the decoded base64 string as the original encoding' do
169- string = "café"
170- string . force_encoding ( "US-ASCII" )
171- expect ( string ) . not_to be_valid_encoding
161+ it 'force encodes the decoded base64 string as the original encoding' do
162+ string = "café"
163+ string . force_encoding ( "US-ASCII" )
164+ expect ( string ) . not_to be_valid_encoding
172165
173- hash [ 'request' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( string . dup ) , 'encoding' => 'US-ASCII' }
174- hash [ 'response' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( string . dup ) , 'encoding' => 'US-ASCII' }
166+ hash [ 'request' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( string . dup ) , 'encoding' => 'US-ASCII' }
167+ hash [ 'response' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( string . dup ) , 'encoding' => 'US-ASCII' }
175168
176- i = HTTPInteraction . from_hash ( hash )
177- expect ( i . request . body . encoding . name ) . to eq ( "US-ASCII" )
178- expect ( i . response . body . encoding . name ) . to eq ( "US-ASCII" )
179- expect ( i . request . body . bytes . to_a ) . to eq ( string . bytes . to_a )
180- expect ( i . response . body . bytes . to_a ) . to eq ( string . bytes . to_a )
181- expect ( i . request . body ) . not_to be_valid_encoding
182- expect ( i . response . body ) . not_to be_valid_encoding
183- end
169+ i = HTTPInteraction . from_hash ( hash )
170+ expect ( i . request . body . encoding . name ) . to eq ( "US-ASCII" )
171+ expect ( i . response . body . encoding . name ) . to eq ( "US-ASCII" )
172+ expect ( i . request . body . bytes . to_a ) . to eq ( string . bytes . to_a )
173+ expect ( i . response . body . bytes . to_a ) . to eq ( string . bytes . to_a )
174+ expect ( i . request . body ) . not_to be_valid_encoding
175+ expect ( i . response . body ) . not_to be_valid_encoding
176+ end
184177
185- it 'does not attempt to force encode the decoded base64 string when there is no encoding given (i.e. if the cassette was recorded on ruby 1.8)' do
186- hash [ 'request' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( 'foo' ) }
178+ it 'does not attempt to force encode the decoded base64 string when there is no encoding given (i.e. if the cassette was recorded on ruby 1.8)' do
179+ hash [ 'request' ] [ 'body' ] = { 'base64_string' => Base64 . encode64 ( 'foo' ) }
187180
188- i = HTTPInteraction . from_hash ( hash )
189- expect ( i . request . body ) . to eq ( 'foo' )
190- expect ( i . request . body . encoding ) . to eq ( Encoding ::BINARY )
191- end
181+ i = HTTPInteraction . from_hash ( hash )
182+ expect ( i . request . body ) . to eq ( 'foo' )
183+ expect ( i . request . body . encoding ) . to eq ( Encoding ::BINARY )
184+ end
192185
193- it 'tries to encode strings to the original encoding' do
194- hash [ 'request' ] [ 'body' ] = { 'string' => "abc" , 'encoding' => 'ISO-8859-1' }
195- hash [ 'response' ] [ 'body' ] = { 'string' => "abc" , 'encoding' => 'ISO-8859-1' }
186+ it 'tries to encode strings to the original encoding' do
187+ hash [ 'request' ] [ 'body' ] = { 'string' => "abc" , 'encoding' => 'ISO-8859-1' }
188+ hash [ 'response' ] [ 'body' ] = { 'string' => "abc" , 'encoding' => 'ISO-8859-1' }
196189
197- i = HTTPInteraction . from_hash ( hash )
198- expect ( i . request . body ) . to eq ( "abc" )
199- expect ( i . response . body ) . to eq ( "abc" )
200- expect ( i . request . body . encoding . name ) . to eq ( "ISO-8859-1" )
201- expect ( i . response . body . encoding . name ) . to eq ( "ISO-8859-1" )
202- end
190+ i = HTTPInteraction . from_hash ( hash )
191+ expect ( i . request . body ) . to eq ( "abc" )
192+ expect ( i . response . body ) . to eq ( "abc" )
193+ expect ( i . request . body . encoding . name ) . to eq ( "ISO-8859-1" )
194+ expect ( i . response . body . encoding . name ) . to eq ( "ISO-8859-1" )
195+ end
203196
204- it 'does not attempt to encode the string when there is no encoding given (i.e. if the cassette was recorded on ruby 1.8)' do
205- string = 'foo'
206- string . force_encoding ( "ISO-8859-1" )
207- hash [ 'request' ] [ 'body' ] = { 'string' => string }
197+ it 'does not attempt to encode the string when there is no encoding given (i.e. if the cassette was recorded on ruby 1.8)' do
198+ string = 'foo'
199+ string . force_encoding ( "ISO-8859-1" )
200+ hash [ 'request' ] [ 'body' ] = { 'string' => string }
208201
209- i = HTTPInteraction . from_hash ( hash )
210- expect ( i . request . body ) . to eq ( 'foo' )
211- expect ( i . request . body . encoding . name ) . to eq ( "ISO-8859-1" )
212- end
202+ i = HTTPInteraction . from_hash ( hash )
203+ expect ( i . request . body ) . to eq ( 'foo' )
204+ expect ( i . request . body . encoding . name ) . to eq ( "ISO-8859-1" )
205+ end
213206
214- it 'force encodes to ASCII-8BIT (since it just means "no encoding" or binary)' do
215- string = "\u00f6 "
216- string . encode ( "UTF-8" )
217- expect ( string ) . to be_valid_encoding
218- hash [ 'request' ] [ 'body' ] = { 'string' => string , 'encoding' => 'ASCII-8BIT' }
207+ it 'force encodes to ASCII-8BIT (since it just means "no encoding" or binary)' do
208+ string = "\u00f6 "
209+ string . encode ( "UTF-8" )
210+ expect ( string ) . to be_valid_encoding
211+ hash [ 'request' ] [ 'body' ] = { 'string' => string , 'encoding' => 'ASCII-8BIT' }
219212
220- expect ( Request ) . not_to receive ( :warn )
221- i = HTTPInteraction . from_hash ( hash )
222- expect ( i . request . body ) . to eq ( string )
223- expect ( i . request . body . bytes . to_a ) . to eq ( string . bytes . to_a )
224- expect ( i . request . body . encoding ) . to eq ( Encoding ::BINARY )
225- end
213+ expect ( Request ) . not_to receive ( :warn )
214+ i = HTTPInteraction . from_hash ( hash )
215+ expect ( i . request . body ) . to eq ( string )
216+ expect ( i . request . body . bytes . to_a ) . to eq ( string . bytes . to_a )
217+ expect ( i . request . body . encoding ) . to eq ( Encoding ::BINARY )
218+ end
226219
227- context 'when the string cannot be encoded as the original encoding' do
228- def verify_encoding_error
229- expect { "\xFA bc" . encode ( "ISO-8859-1" ) } . to raise_error ( EncodingError )
230- end
220+ context 'when the string cannot be encoded as the original encoding' do
221+ def verify_encoding_error
222+ expect { "\xFA bc" . encode ( "ISO-8859-1" ) } . to raise_error ( EncodingError )
223+ end
231224
232- before do
233- allow ( Request ) . to receive ( :warn )
234- allow ( Response ) . to receive ( :warn )
225+ before do
226+ allow ( Request ) . to receive ( :warn )
227+ allow ( Response ) . to receive ( :warn )
235228
236- hash [ 'request' ] [ 'body' ] = { 'string' => "\xFA bc" , 'encoding' => 'ISO-8859-1' }
237- hash [ 'response' ] [ 'body' ] = { 'string' => "\xFA bc" , 'encoding' => 'ISO-8859-1' }
229+ hash [ 'request' ] [ 'body' ] = { 'string' => "\xFA bc" , 'encoding' => 'ISO-8859-1' }
230+ hash [ 'response' ] [ 'body' ] = { 'string' => "\xFA bc" , 'encoding' => 'ISO-8859-1' }
238231
239- verify_encoding_error
240- end
232+ verify_encoding_error
233+ end
241234
242- it 'does not force the encoding' do
243- i = HTTPInteraction . from_hash ( hash )
244- expect ( i . request . body ) . to eq ( "\xFA bc" )
245- expect ( i . response . body ) . to eq ( "\xFA bc" )
246- expect ( i . request . body . encoding . name ) . not_to eq ( "ISO-8859-1" )
247- expect ( i . response . body . encoding . name ) . not_to eq ( "ISO-8859-1" )
248- end
235+ it 'does not force the encoding' do
236+ i = HTTPInteraction . from_hash ( hash )
237+ expect ( i . request . body ) . to eq ( "\xFA bc" )
238+ expect ( i . response . body ) . to eq ( "\xFA bc" )
239+ expect ( i . request . body . encoding . name ) . not_to eq ( "ISO-8859-1" )
240+ expect ( i . response . body . encoding . name ) . not_to eq ( "ISO-8859-1" )
241+ end
249242
250- it 'prints a warning and informs users of the :preserve_exact_body_bytes option' do
251- expect ( Request ) . to receive ( :warn ) . with ( /ISO-8859-1.*preserve_exact_body_bytes/ )
252- expect ( Response ) . to receive ( :warn ) . with ( /ISO-8859-1.*preserve_exact_body_bytes/ )
243+ it 'prints a warning and informs users of the :preserve_exact_body_bytes option' do
244+ expect ( Request ) . to receive ( :warn ) . with ( /ISO-8859-1.*preserve_exact_body_bytes/ )
245+ expect ( Response ) . to receive ( :warn ) . with ( /ISO-8859-1.*preserve_exact_body_bytes/ )
253246
254- HTTPInteraction . from_hash ( hash )
255- end
247+ HTTPInteraction . from_hash ( hash )
256248 end
257249 end
258250 end
@@ -316,7 +308,7 @@ def verify_encoding_error
316308 expect ( hash [ 'response' ] [ 'body' ] ) . to eq ( body_hash ( 'base64_string' , Base64 . encode64 ( 'res body' ) ) )
317309 end
318310
319- it "sets the string's original encoding" , :if => '' . respond_to? ( :encoding ) do
311+ it "sets the string's original encoding" do
320312 interaction . request . body . force_encoding ( 'ISO-8859-10' )
321313 interaction . response . body . force_encoding ( Encoding ::BINARY )
322314
@@ -744,4 +736,3 @@ def instance(body)
744736 end
745737 end
746738end
747-
0 commit comments