Commits

Michael Granger committed f727ec4

Convert httpresponse/negotiation spec to expect syntax

Comments (0)

Files changed (1)

spec/strelka/httpresponse/negotiation_spec.rb

 		@res.puts( "FOOM!" )
 		@res.content_type = 'text/plain'
 		@res.charset = Encoding::UTF_8
-		@res.to_s.should include(
+		expect( @res.to_s ).to include(
 			'HTTP/1.1 200 OK',
 			'Content-Length: 6',
 			'Content-Type: text/plain; charset=UTF-8',
 			@res.for( 'application/x-yaml' ) { { 'a' => "YAML dump" } }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "---\na: YAML dump\n"
-			@res.content_type.should == "application/x-yaml"
-			@res.header_data.should =~ /accept(?!-)/i
+			expect( @res.negotiated_body.read ).to eq( "---\na: YAML dump\n" )
+			expect( @res.content_type ).to eq( "application/x-yaml" )
+			expect( @res.header_data ).to match( /accept(?!-)/i )
 		end
 
 		it "can provide a single block for bodies of several different mediatypes" do
 			end
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
-				"\"name\":\"Harlot's Garden\"}"
-			@res.content_type.should == "application/json"
-			@res.header_data.should =~ /accept(?!-)/i
+			expect( @res.negotiated_body.read ).
+				to eq( "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
+				       "\"name\":\"Harlot's Garden\"}" )
+			expect( @res.content_type ).to eq( "application/json" )
+			expect( @res.header_data ).to match( /accept(?!-)/i )
 		end
 
 		it "can provide a block for bodies of several different symbolic mediatypes" do
 			end
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
-				"\"name\":\"Harlot's Garden\"}"
-			@res.content_type.should == "application/json"
-			@res.header_data.should =~ /accept(?!-)/i
+			expect( @res.negotiated_body.read ).
+				to eq( "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
+				       "\"name\":\"Harlot's Garden\"}" )
+			expect( @res.content_type ).to eq( "application/json" )
+			expect( @res.header_data ).to match( /accept(?!-)/i )
 		end
 
 		it "raises an exception if given a block for an unknown symbolic mediatype" do
 			@res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
 			@res.content_type = 'text/plain'
 
-			@res.negotiated_body.external_encoding.should == Encoding::KOI8_R
-			@res.header_data.should =~ /accept-charset(?!-)/i
+			expect( @res.negotiated_body.external_encoding ).to eq( Encoding::KOI8_R )
+			expect( @res.header_data ).to match( /accept-charset(?!-)/i )
 		end
 
 		it "transcodes String entity bodies if the charset is not acceptable" do
 			@res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
 			@res.content_type = 'application/json'
 
-			@res.negotiated_body.external_encoding.should == Encoding::UTF_8
-			@res.header_data.should =~ /accept-charset(?!-)/i
+			expect( @res.negotiated_body.external_encoding ).to eq( Encoding::UTF_8 )
+			expect( @res.header_data ).to match( /accept-charset(?!-)/i )
 		end
 
 		it "transcodes File entity bodies if the charset is not acceptable" do
 				@res.body = File.open( __FILE__, 'r:iso-8859-5' )
 				@res.content_type = 'text/plain'
 
-				@res.negotiated_body.read.encoding.should == Encoding::KOI8_R
-				@res.header_data.should =~ /accept-charset(?!-)/i
+				expect( @res.negotiated_body.read.encoding ).to eq( Encoding::KOI8_R )
+				expect( @res.header_data ).to match( /accept-charset(?!-)/i )
 			end
 		end
 
 			@res.for_language( :sl ) { "Slovenian translation" }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "German translation"
-			@res.languages.should == ["de"]
-			@res.header_data.should =~ /accept-language/i
+			expect( @res.negotiated_body.read ).to eq( "German translation" )
+			expect( @res.languages ).to eq( ["de"] )
+			expect( @res.header_data ).to match( /accept-language/i )
 		end
 
 		it "can provide blocks for bodies of several different languages without setting a " +
 			@res.for_language( :sl ) { "Slovenian translation" }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "German translation"
-			@res.languages.should == ["de"]
-			@res.header_data.should =~ /accept-language/i
+			expect( @res.negotiated_body.read ).to eq( "German translation" )
+			expect( @res.languages ).to eq( ["de"] )
+			expect( @res.header_data ).to match( /accept-language/i )
 		end
 
 		it "can provide a single block for bodies of several different languages" do
 			end
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "Portuguese translation"
-			@res.languages.should == ["pt"]
-			@res.header_data.should =~ /accept-language/i
+			expect( @res.negotiated_body.read ).to eq( "Portuguese translation" )
+			expect( @res.languages ).to eq( ["pt"] )
+			expect( @res.header_data ).to match( /accept-language/i )
 		end
 
 		it "calls the first block for requests with no accept-language header" do
 			@res.for_language( :sl ) { "Slovenian translation" }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "English translation"
-			@res.languages.should == ["en"]
-			@res.header_data.should =~ /accept-language/i
+			expect( @res.negotiated_body.read ).to eq( "English translation" )
+			expect( @res.languages ).to eq( ["en"] )
+			expect( @res.header_data ).to match( /accept-language/i )
 		end
 	end
 
 			@res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "the text body (gzipped)"
-			@res.encodings.should include( "gzip" )
-			@res.header_data.should =~ /accept-encoding/i
-			@res.header_data.should_not =~ /identity/i
+			expect( @res.negotiated_body.read ).to eq( "the text body (gzipped)" )
+			expect( @res.encodings ).to include( "gzip" )
+			expect( @res.header_data ).to match( /accept-encoding/i )
+			expect( @res.header_data ).to_not match( /identity/i )
 		end
 
 		it "chooses the content coding with the highest qvalue" do
 			@res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
 
 			@res.negotiated_body.rewind
-			@res.negotiated_body.read.should == "the text body (deflated)"
-			@res.encodings.should include( "deflate" )
-			@res.header_data.should =~ /accept-encoding/i
-			@res.header_data.should_not =~ /identity/i
+			expect( @res.negotiated_body.read ).to eq( "the text body (deflated)" )
+			expect( @res.encodings ).to include( "deflate" )
+			expect( @res.header_data ).to match( /accept-encoding/i )
+			expect( @res.header_data ).to_not match( /identity/i )
 		end
 
 	end
 			@req.headers.accept = 'application/x-yaml, application/json; q=0.7'
 			@res.content_type = 'application/json'
 
-			@res.should have_acceptable_content_type()
+			expect( @res ).to have_acceptable_content_type
 		end
 
 		it "knows that it is acceptable if its request doesn't have accepted types" do
 			@req.headers.delete( :accept )
 			@res.content_type = 'application/x-ruby-marshalled'
 
-			@res.should have_acceptable_content_type()
+			expect( @res ).to have_acceptable_content_type
 		end
 
 		it "knows that it is acceptable if it doesn't have an originating request" do
 			res.extend( Strelka::HTTPResponse::Negotiation )
 			res.content_type = 'application/x-ruby-marshalled'
 
-			res.should have_acceptable_content_type()
+			expect( res ).to have_acceptable_content_type
 		end
 
 		it "knows that it is not acceptable if its content_type isn't in the list of " +
 			@req.headers.accept = 'application/x-yaml, application/json; q=0.7'
 			@res.content_type = 'application/x-ruby-marshalled'
 
-			@res.should_not have_acceptable_content_type()
+			expect( @res ).to_not have_acceptable_content_type
 		end
 
 	end
 			@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
 			@res.charset = 'iso-8859-5'
 
-			@res.should have_acceptable_charset()
+			expect( @res ).to have_acceptable_charset()
 		end
 
 		it "knows that it is acceptable if its request doesn't have accepted types" do
 			@req.headers.delete( :accept_charset )
 			@res.charset = 'koi8-u'
-			@res.should have_acceptable_charset()
+			expect( @res ).to have_acceptable_charset()
 		end
 
 		it "knows that it is acceptable if it doesn't have an originating request" do
 			res = Strelka::HTTPResponse.new( 'appid', 88 )
 			res.charset = 'iso8859-15'
 
-			res.should have_acceptable_charset()
+			expect( res ).to have_acceptable_charset()
 		end
 
 		it "knows that it is acceptable if its explicit charset is set to ascii-8bit" do
 			@res.content_type = 'image/jpeg'
 			@res.charset = Encoding::ASCII_8BIT
 
-			@res.should have_acceptable_charset()
+			expect( @res ).to have_acceptable_charset()
 		end
 
 		it "knows that it is acceptable if no charset can be derived, but the list of " +
 			@res.content_type = 'text/plain'
 			@res.body = "some stuff".force_encoding( Encoding::ASCII_8BIT )
 
-			@res.should have_acceptable_charset()
+			expect( @res ).to have_acceptable_charset()
 		end
 
 		it "knows that it is not acceptable if no charset can be derived, the content is a " +
 			@res.content_type = 'text/plain'
 			@res.body = "some stuff".force_encoding( Encoding::ASCII_8BIT )
 
-			@res.should_not have_acceptable_charset()
+			expect( @res ).to_not have_acceptable_charset()
 		end
 
 		it "knows that it is not acceptable if its explicit charset isn't in the list of " +
 			@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
 			@res.charset = 'sjis'
 
-			@res.should_not have_acceptable_charset()
+			expect( @res ).to_not have_acceptable_charset()
 		end
 
 		it "knows that it is not acceptable if the charset in its content-type header isn't in " +
 			@req.headers.accept_charset = 'iso-8859-5, utf-8;q=0.8'
 			@res.content_type = 'text/plain; charset=sjis'
 
-			@res.should_not have_acceptable_charset()
+			expect( @res ).to_not have_acceptable_charset()
 		end
 
 		it "knows that it is not acceptable if the charset derived from its entity body isn't in " +
 			@res.content_type = 'text/plain'
 			@res.body = File.open( __FILE__, 'r:iso8859-5' )
 
-			@res.should_not have_acceptable_charset()
+			expect( @res ).to_not have_acceptable_charset()
 		end
 
 	end
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages << 'ja'
 
-			@res.should have_acceptable_language()
+			expect( @res ).to have_acceptable_language()
 		end
 
 		it "knows that it is acceptable if all of its multiple languages are in the list of " +
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages << 'ja' << 'en-us'
 
-			@res.should have_acceptable_language()
+			expect( @res ).to have_acceptable_language()
 		end
 
 		# I'm not sure if this is what RFC1616 means. It might be that *all* of its languages
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages << 'pt' << 'en'
 
-			@res.should have_acceptable_language()
+			expect( @res ).to have_acceptable_language()
 		end
 
 		it "knows that it is acceptable if it has a body but doesn't have a language set" do
 			@res.languages.clear
 			@res.puts( "Some content in an unspecified language." )
 
-			@res.should have_acceptable_language()
+			expect( @res ).to have_acceptable_language()
 		end
 
 		it "knows that it is acceptable if it has no body yet" do
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages.clear
 
-			@res.should have_acceptable_language()
+			expect( @res ).to have_acceptable_language()
 		end
 
 		it "knows that it is acceptable if it doesn't have an originating request" do
 			res.extend( Strelka::HTTPResponse::Negotiation )
 			res.languages << 'kh'
 
-			res.should have_acceptable_language()
+			expect( res ).to have_acceptable_language()
 		end
 
 		it "knows that it is not acceptable if it has a single language that isn't in the " +
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages << 'pt'
 
-			@res.should_not have_acceptable_language()
+			expect( @res ).to_not have_acceptable_language()
 		end
 
 		it "knows that it is not acceptable if it has multiple languages, none of which are " +
 			@req.headers.accept_language = 'en-gb, en; q=0.7, ja;q=0.2'
 			@res.languages << 'pt-br' << 'fr-ca'
 
-			@res.should_not have_acceptable_language()
+			expect( @res ).to_not have_acceptable_language()
 		end
 
 	end
 			@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
 			@res.encodings << 'gzip'
 
-			@res.should have_acceptable_encoding()
+			expect( @res ).to have_acceptable_encoding()
 		end
 
 		it "knows that it is acceptable if all of its content codings are in the list of accepted " +
 			@req.headers.accept_encoding = 'gzip;q=1.0, frobnify;q=0.9, identity; q=0.5, *;q=0'
 			@res.encodings << 'gzip' << 'frobnify'
 
-			@res.should have_acceptable_encoding()
+			expect( @res ).to have_acceptable_encoding()
 		end
 
 		it "knows that it is not acceptable if one of its content codings is not in the list " +
 			@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0.5, *;q=0'
 			@res.encodings << 'gzip' << 'frobnify'
 
-			@res.should_not have_acceptable_encoding()
+			expect( @res ).to_not have_acceptable_encoding()
 		end
 
 		it "knows that it is not acceptable if it doesn't have any explicit content codings " +
 			@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
 			@res.encodings.clear
 
-			@res.should_not have_acceptable_encoding()
+			expect( @res ).to_not have_acceptable_encoding()
 		end
 
 		it "knows that it is not acceptable if it doesn't have any explicit content codings " +
 			@req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
 			@res.encodings.clear
 
-			@res.should_not have_acceptable_encoding()
+			expect( @res ).to_not have_acceptable_encoding()
 		end
 
 		it "knows that it is not acceptable if it doesn't have any explicit content codings, " +
 			@req.headers.accept_encoding = 'gzip;q=1.0, *;q=0'
 			@res.encodings.clear
 
-			@res.should_not have_acceptable_encoding()
+			expect( @res ).to_not have_acceptable_encoding()
 		end
 
 	end