1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
|
From: Antonio Terceiro <terceiro@debian.org>
Date: Fri, 14 Aug 2015 11:29:16 -0300
Subject: Port to rspec 3
Used transpec + some manual tweaks
---
spec/rack/test/cookie_spec.rb | 98 ++++++++++----------
spec/rack/test/digest_auth_spec.rb | 10 +--
spec/rack/test/multipart_spec.rb | 48 +++++-----
spec/rack/test/uploaded_file_spec.rb | 22 ++---
spec/rack/test/utils_spec.rb | 82 ++++++++---------
spec/rack/test_spec.rb | 168 +++++++++++++++++------------------
spec/spec_helper.rb | 18 ++--
spec/support/matchers/body.rb | 2 +-
8 files changed, 223 insertions(+), 225 deletions(-)
diff --git a/spec/rack/test/cookie_spec.rb b/spec/rack/test/cookie_spec.rb
index e4bce5a..e0839e5 100644
--- a/spec/rack/test/cookie_spec.rb
+++ b/spec/rack/test/cookie_spec.rb
@@ -5,90 +5,88 @@ describe Rack::Test::Session do
context "cookies" do
it "keeps a cookie jar" do
get "/cookies/show"
- check last_request.cookies.should == {}
+ check expect(last_request.cookies).to eq({})
get "/cookies/set", "value" => "1"
get "/cookies/show"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
it "doesn't send expired cookies" do
get "/cookies/set", "value" => "1"
now = Time.now
- Time.stub!(:now => now + 60)
+ allow(Time).to receive_messages(:now => now + 60)
get "/cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "cookie path defaults to the uri of the document that was requested" do
- pending "See issue rack-test github issue #50" do
- post "/cookies/default-path", "value" => "cookie"
- get "/cookies/default-path"
- check last_request.cookies.should == { "simple"=>"cookie" }
- get "/cookies/show"
- check last_request.cookies.should == { }
- end
+ pending "See issue rack-test github issue #50"
+ post "/cookies/default-path", "value" => "cookie"
+ get "/cookies/default-path"
+ expect(last_request.cookies).to eq({ "simple"=>"cookie" })
+ get "/cookies/show"
+ expect(last_request.cookies).to eq({})
end
it "escapes cookie values" do
jar = Rack::Test::CookieJar.new
jar["value"] = "foo;abc"
- jar["value"].should == "foo;abc"
+ expect(jar["value"]).to eq("foo;abc")
end
it "deletes cookies directly from the CookieJar" do
jar = Rack::Test::CookieJar.new
jar["abcd"] = "1234"
- jar["abcd"].should == "1234"
+ expect(jar["abcd"]).to eq("1234")
jar.delete("abcd")
- jar["abcd"].should == nil
+ expect(jar["abcd"]).to eq(nil)
end
it "doesn't send cookies with the wrong domain" do
get "http://www.example.com/cookies/set", "value" => "1"
get "http://www.other.example/cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "doesn't send cookies with the wrong path" do
get "/cookies/set", "value" => "1"
get "/not-cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "persists cookies across requests that don't return any cookie headers" do
get "/cookies/set", "value" => "1"
get "/void"
get "/cookies/show"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
it "deletes cookies" do
get "/cookies/set", "value" => "1"
get "/cookies/delete"
get "/cookies/show"
- last_request.cookies.should == { }
+ expect(last_request.cookies).to eq({ })
end
it "respects cookie domains when no domain is explicitly set" do
- pending "FIXME: www.example.org should not get the first cookie" do
- request("http://example.org/cookies/count").should have_body("1")
- request("http://www.example.org/cookies/count").should have_body("1")
- request("http://example.org/cookies/count").should have_body("2")
- request("http://www.example.org/cookies/count").should have_body("2")
- end
+ pending "FIXME: www.example.org should not get the first cookie"
+ expect(request("http://example.org/cookies/count")).to have_body("1")
+ expect(request("http://www.example.org/cookies/count")).to have_body("1")
+ expect(request("http://example.org/cookies/count")).to have_body("2")
+ expect(request("http://www.example.org/cookies/count")).to have_body("2")
end
it "treats domains case insensitively" do
get "http://example.com/cookies/set", "value" => "1"
get "http://EXAMPLE.COM/cookies/show"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
it "treats paths case sensitively" do
get "/cookies/set", "value" => "1"
get "/COOKIES/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "prefers more specific cookies" do
@@ -96,124 +94,124 @@ describe Rack::Test::Session do
get "http://sub.example.com/cookies/set", "value" => "sub"
get "http://sub.example.com/cookies/show"
- check last_request.cookies.should == { "value" => "sub" }
+ check expect(last_request.cookies).to eq({ "value" => "sub" })
get "http://example.com/cookies/show"
- last_request.cookies.should == { "value" => "domain" }
+ expect(last_request.cookies).to eq({ "value" => "domain" })
end
it "treats cookie names case insensitively" do
get "/cookies/set", "value" => "lowercase"
get "/cookies/set-uppercase", "value" => "UPPERCASE"
get "/cookies/show"
- last_request.cookies.should == { "VALUE" => "UPPERCASE" }
+ expect(last_request.cookies).to eq({ "VALUE" => "UPPERCASE" })
end
it "defaults the domain to the request domain" do
get "http://example.com/cookies/set-simple", "value" => "cookie"
get "http://example.com/cookies/show"
- check last_request.cookies.should == { "simple" => "cookie" }
+ check expect(last_request.cookies).to eq({ "simple" => "cookie" })
get "http://other.example/cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "defaults the domain to the request path up to the last slash" do
get "/cookies/set-simple", "value" => "1"
get "/not-cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "supports secure cookies" do
get "https://example.com/cookies/set-secure", "value" => "set"
get "http://example.com/cookies/show"
- check last_request.cookies.should == {}
+ check expect(last_request.cookies).to eq({})
get "https://example.com/cookies/show"
- last_request.cookies.should == { "secure-cookie" => "set" }
- rack_mock_session.cookie_jar['secure-cookie'].should == 'set'
+ expect(last_request.cookies).to eq({ "secure-cookie" => "set" })
+ expect(rack_mock_session.cookie_jar['secure-cookie']).to eq('set')
end
it "keeps separate cookie jars for different domains" do
get "http://example.com/cookies/set", "value" => "example"
get "http://example.com/cookies/show"
- check last_request.cookies.should == { "value" => "example" }
+ check expect(last_request.cookies).to eq({ "value" => "example" })
get "http://other.example/cookies/set", "value" => "other"
get "http://other.example/cookies/show"
- check last_request.cookies.should == { "value" => "other" }
+ check expect(last_request.cookies).to eq({ "value" => "other" })
get "http://example.com/cookies/show"
- last_request.cookies.should == { "value" => "example" }
+ expect(last_request.cookies).to eq({ "value" => "example" })
end
it "keeps one cookie jar for domain and its subdomains" do
get "http://example.org/cookies/subdomain"
get "http://example.org/cookies/subdomain"
- last_request.cookies.should == { "count" => "1" }
+ expect(last_request.cookies).to eq({ "count" => "1" })
get "http://foo.example.org/cookies/subdomain"
- last_request.cookies.should == { "count" => "2" }
+ expect(last_request.cookies).to eq({ "count" => "2" })
end
it "allows cookies to be cleared" do
get "/cookies/set", "value" => "1"
clear_cookies
get "/cookies/show"
- last_request.cookies.should == {}
+ expect(last_request.cookies).to eq({})
end
it "allow cookies to be set" do
set_cookie "value=10"
get "/cookies/show"
- last_request.cookies.should == { "value" => "10" }
+ expect(last_request.cookies).to eq({ "value" => "10" })
end
it "allows an array of cookies to be set" do
set_cookie ["value=10", "foo=bar"]
get "/cookies/show"
- last_request.cookies.should == { "value" => "10", "foo" => "bar" }
+ expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
end
it "skips emtpy string cookies" do
set_cookie "value=10\n\nfoo=bar"
get "/cookies/show"
- last_request.cookies.should == { "value" => "10", "foo" => "bar" }
+ expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
end
it "parses multiple cookies properly" do
get "/cookies/set-multiple"
get "/cookies/show"
- last_request.cookies.should == { "key1" => "value1", "key2" => "value2" }
+ expect(last_request.cookies).to eq({ "key1" => "value1", "key2" => "value2" })
end
it "supports multiple sessions" do
with_session(:first) do
get "/cookies/set", "value" => "1"
get "/cookies/show"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
with_session(:second) do
get "/cookies/show"
- last_request.cookies.should == { }
+ expect(last_request.cookies).to eq({ })
end
end
it "uses :default as the default session name" do
get "/cookies/set", "value" => "1"
get "/cookies/show"
- check last_request.cookies.should == { "value" => "1" }
+ check expect(last_request.cookies).to eq({ "value" => "1" })
with_session(:default) do
get "/cookies/show"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
end
it "accepts explicitly provided cookies" do
request "/cookies/show", :cookie => "value=1"
- last_request.cookies.should == { "value" => "1" }
+ expect(last_request.cookies).to eq({ "value" => "1" })
end
end
end
diff --git a/spec/rack/test/digest_auth_spec.rb b/spec/rack/test/digest_auth_spec.rb
index 7b966e6..cccf1d6 100644
--- a/spec/rack/test/digest_auth_spec.rb
+++ b/spec/rack/test/digest_auth_spec.rb
@@ -15,31 +15,31 @@ describe Rack::Test::Session do
it 'incorrectly authenticates GETs' do
digest_authorize 'foo', 'bar'
get '/'
- last_response.should be_challenge
+ expect(last_response).to be_challenge
end
it "correctly authenticates GETs" do
digest_authorize "alice", "correct-password"
response = get "/"
- response.should be_ok
+ expect(response).to be_ok
end
it "correctly authenticates GETs with params" do
digest_authorize "alice", "correct-password"
response = get "/", "foo" => "bar"
- response.should be_ok
+ expect(response).to be_ok
end
it "correctly authenticates POSTs" do
digest_authorize "alice", "correct-password"
response = post "/"
- response.should be_ok
+ expect(response).to be_ok
end
it "returns a re-challenge if authenticating incorrectly" do
digest_authorize "alice", "incorrect-password"
response = get "/"
- response.should be_challenge
+ expect(response).to be_challenge
end
end
diff --git a/spec/rack/test/multipart_spec.rb b/spec/rack/test/multipart_spec.rb
index ad6c3ae..2e7bf16 100644
--- a/spec/rack/test/multipart_spec.rb
+++ b/spec/rack/test/multipart_spec.rb
@@ -23,83 +23,83 @@ describe Rack::Test::Session do
context "uploading a file" do
it "sends the multipart/form-data content type" do
post "/", "photo" => uploaded_file
- last_request.env["CONTENT_TYPE"].should include("multipart/form-data;")
+ expect(last_request.env["CONTENT_TYPE"]).to include("multipart/form-data;")
end
it "sends regular params" do
post "/", "photo" => uploaded_file, "foo" => "bar"
- last_request.POST["foo"].should == "bar"
+ expect(last_request.POST["foo"]).to eq("bar")
end
it "sends nested params" do
post "/", "photo" => uploaded_file, "foo" => {"bar" => "baz"}
- last_request.POST["foo"]["bar"].should == "baz"
+ expect(last_request.POST["foo"]["bar"]).to eq("baz")
end
it "sends multiple nested params" do
post "/", "photo" => uploaded_file, "foo" => {"bar" => {"baz" => "bop"}}
- last_request.POST["foo"]["bar"]["baz"].should == "bop"
+ expect(last_request.POST["foo"]["bar"]["baz"]).to eq("bop")
end
it "sends params with arrays" do
post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
- last_request.POST["foo"].should == ["1", "2"]
+ expect(last_request.POST["foo"]).to eq(["1", "2"])
end
it "sends params with encoding sensitive values" do
post "/", "photo" => uploaded_file, "foo" => "bar? baz"
- last_request.POST["foo"].should == "bar? baz"
+ expect(last_request.POST["foo"]).to eq("bar? baz")
end
it "sends params encoded as ISO-8859-1" do
post "/", "photo" => uploaded_file, "foo" => "bar", "utf8" => "☃"
- last_request.POST["foo"].should == "bar"
+ expect(last_request.POST["foo"]).to eq("bar")
if Rack::Test.encoding_aware_strings?
- last_request.POST["utf8"].should == "☃"
+ expect(last_request.POST["utf8"]).to eq("☃")
else
- last_request.POST["utf8"].should == "\xE2\x98\x83"
+ expect(last_request.POST["utf8"]).to eq("\xE2\x98\x83")
end
end
it "sends params with parens in names" do
post "/", "photo" => uploaded_file, "foo(1i)" => "bar"
- last_request.POST["foo(1i)"].should == "bar"
+ expect(last_request.POST["foo(1i)"]).to eq("bar")
end
it "sends params with encoding sensitive names" do
post "/", "photo" => uploaded_file, "foo bar" => "baz"
- last_request.POST["foo bar"].should == "baz"
+ expect(last_request.POST["foo bar"]).to eq("baz")
end
it "sends files with the filename" do
post "/", "photo" => uploaded_file
- last_request.POST["photo"][:filename].should == "foo.txt"
+ expect(last_request.POST["photo"][:filename]).to eq("foo.txt")
end
it "sends files with the text/plain MIME type by default" do
post "/", "photo" => uploaded_file
- last_request.POST["photo"][:type].should == "text/plain"
+ expect(last_request.POST["photo"][:type]).to eq("text/plain")
end
it "sends files with the right name" do
post "/", "photo" => uploaded_file
- last_request.POST["photo"][:name].should == "photo"
+ expect(last_request.POST["photo"][:name]).to eq("photo")
end
it "allows overriding the content type" do
post "/", "photo" => Rack::Test::UploadedFile.new(test_file_path, "image/jpeg")
- last_request.POST["photo"][:type].should == "image/jpeg"
+ expect(last_request.POST["photo"][:type]).to eq("image/jpeg")
end
it "sends files with a Content-Length in the header" do
post "/", "photo" => uploaded_file
- last_request.POST["photo"][:head].should include("Content-Length: 4")
+ expect(last_request.POST["photo"][:head]).to include("Content-Length: 4")
end
it "sends files as Tempfiles" do
post "/", "photo" => uploaded_file
- last_request.POST["photo"][:tempfile].should be_a(::Tempfile)
+ expect(last_request.POST["photo"][:tempfile]).to be_a(::Tempfile)
end
end
@@ -107,39 +107,39 @@ describe Rack::Test::Session do
context "uploading two files" do
it "sends the multipart/form-data content type" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.env["CONTENT_TYPE"].should include("multipart/form-data;")
+ expect(last_request.env["CONTENT_TYPE"]).to include("multipart/form-data;")
end
it "sends files with the filename" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.POST["photos"].collect{|photo| photo[:filename]}.should == ["foo.txt", "bar.txt"]
+ expect(last_request.POST["photos"].collect{|photo| photo[:filename]}).to eq(["foo.txt", "bar.txt"])
end
it "sends files with the text/plain MIME type by default" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.POST["photos"].collect{|photo| photo[:type]}.should == ["text/plain", "text/plain"]
+ expect(last_request.POST["photos"].collect{|photo| photo[:type]}).to eq(["text/plain", "text/plain"])
end
it "sends files with the right names" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.POST["photos"].all?{|photo| photo[:name].should == "photos[]" }
+ last_request.POST["photos"].all?{|photo| expect(photo[:name]).to eq("photos[]") }
end
it "allows mixed content types" do
image_file = Rack::Test::UploadedFile.new(test_file_path, "image/jpeg")
post "/", "photos" => [uploaded_file, image_file]
- last_request.POST["photos"].collect{|photo| photo[:type]}.should == ["text/plain", "image/jpeg"]
+ expect(last_request.POST["photos"].collect{|photo| photo[:type]}).to eq(["text/plain", "image/jpeg"])
end
it "sends files with a Content-Length in the header" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.POST["photos"].all?{|photo| photo[:head].should include("Content-Length: 4") }
+ last_request.POST["photos"].all?{|photo| expect(photo[:head]).to include("Content-Length: 4") }
end
it "sends both files as Tempfiles" do
post "/", "photos" => [uploaded_file, second_uploaded_file]
- last_request.POST["photos"].all?{|photo| photo[:tempfile].should be_a(::Tempfile) }
+ last_request.POST["photos"].all?{|photo| expect(photo[:tempfile]).to be_a(::Tempfile) }
end
end
end
diff --git a/spec/rack/test/uploaded_file_spec.rb b/spec/rack/test/uploaded_file_spec.rb
index cde4856..8439735 100644
--- a/spec/rack/test/uploaded_file_spec.rb
+++ b/spec/rack/test/uploaded_file_spec.rb
@@ -8,17 +8,17 @@ describe Rack::Test::UploadedFile do
it "responds to things that Tempfile responds to" do
uploaded_file = Rack::Test::UploadedFile.new(test_file_path)
- uploaded_file.should respond_to(:close)
- uploaded_file.should respond_to(:close!)
- uploaded_file.should respond_to(:delete)
- uploaded_file.should respond_to(:length)
- uploaded_file.should respond_to(:open)
- uploaded_file.should respond_to(:path)
- uploaded_file.should respond_to(:size)
- uploaded_file.should respond_to(:unlink)
- uploaded_file.should respond_to(:read)
- uploaded_file.should respond_to(:original_filename)
- uploaded_file.should respond_to(:tempfile) # Allows calls to params[:file].tempfile
+ expect(uploaded_file).to respond_to(:close)
+ expect(uploaded_file).to respond_to(:close!)
+ expect(uploaded_file).to respond_to(:delete)
+ expect(uploaded_file).to respond_to(:length)
+ expect(uploaded_file).to respond_to(:open)
+ expect(uploaded_file).to respond_to(:path)
+ expect(uploaded_file).to respond_to(:size)
+ expect(uploaded_file).to respond_to(:unlink)
+ expect(uploaded_file).to respond_to(:read)
+ expect(uploaded_file).to respond_to(:original_filename)
+ expect(uploaded_file).to respond_to(:tempfile) # Allows calls to params[:file].tempfile
end
end
diff --git a/spec/rack/test/utils_spec.rb b/spec/rack/test/utils_spec.rb
index 3b27767..b5e70e1 100644
--- a/spec/rack/test/utils_spec.rb
+++ b/spec/rack/test/utils_spec.rb
@@ -5,48 +5,48 @@ describe Rack::Test::Utils do
describe "build_nested_query" do
it "converts empty strings to =" do
- build_nested_query("").should == "="
+ expect(build_nested_query("")).to eq("=")
end
it "converts nil to an empty string" do
- build_nested_query(nil).should == ""
+ expect(build_nested_query(nil)).to eq("")
end
it "converts hashes with nil values" do
- build_nested_query(:a => nil).should == "a"
+ expect(build_nested_query(:a => nil)).to eq("a")
end
it "converts hashes" do
- build_nested_query(:a => 1).should == "a=1"
+ expect(build_nested_query(:a => 1)).to eq("a=1")
end
it "converts hashes with multiple keys" do
hash = { :a => 1, :b => 2 }
- ["a=1&b=2", "b=2&a=1"].should include(build_nested_query(hash))
+ expect(["a=1&b=2", "b=2&a=1"]).to include(build_nested_query(hash))
end
it "converts arrays with one element" do
- build_nested_query(:a => [1]).should == "a[]=1"
+ expect(build_nested_query(:a => [1])).to eq("a[]=1")
end
it "converts arrays with multiple elements" do
- build_nested_query(:a => [1, 2]).should == "a[]=1&a[]=2"
+ expect(build_nested_query(:a => [1, 2])).to eq("a[]=1&a[]=2")
end
it "converts arrays with brackets '[]' in the name" do
- build_nested_query("a[]" => [1, 2]).should == "a%5B%5D=1&a%5B%5D=2"
+ expect(build_nested_query("a[]" => [1, 2])).to eq("a%5B%5D=1&a%5B%5D=2")
end
it "converts nested hashes" do
- build_nested_query(:a => { :b => 1 }).should == "a[b]=1"
+ expect(build_nested_query(:a => { :b => 1 })).to eq("a[b]=1")
end
it "converts arrays nested in a hash" do
- build_nested_query(:a => { :b => [1, 2] }).should == "a[b][]=1&a[b][]=2"
+ expect(build_nested_query(:a => { :b => [1, 2] })).to eq("a[b][]=1&a[b][]=2")
end
it "converts arrays of hashes" do
- build_nested_query(:a => [{ :b => 2}, { :c => 3}]).should == "a[][b]=2&a[][c]=3"
+ expect(build_nested_query(:a => [{ :b => 2}, { :c => 3}])).to eq("a[][b]=2&a[][c]=3")
end
end
@@ -62,9 +62,9 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["submit-name"].should == "Larry"
- check params["files"][:filename].should == "foo.txt"
- params["files"][:tempfile].read.should == "bar\n"
+ check expect(params["submit-name"]).to eq("Larry")
+ check expect(params["files"][:filename]).to eq("foo.txt")
+ expect(params["files"][:tempfile].read).to eq("bar\n")
end
it "builds multipart bodies from array of files" do
@@ -78,13 +78,13 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["submit-name"].should == "Larry"
+ check expect(params["submit-name"]).to eq("Larry")
- check params["files"][0][:filename].should == "foo.txt"
- params["files"][0][:tempfile].read.should == "bar\n"
+ check expect(params["files"][0][:filename]).to eq("foo.txt")
+ expect(params["files"][0][:tempfile].read).to eq("bar\n")
- check params["files"][1][:filename].should == "bar.txt"
- params["files"][1][:tempfile].read.should == "baz\n"
+ check expect(params["files"][1][:filename]).to eq("bar.txt")
+ expect(params["files"][1][:tempfile].read).to eq("baz\n")
end
it "builds nested multipart bodies" do
@@ -98,10 +98,10 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["people"][0]["submit-name"].should == "Larry"
- check params["people"][0]["files"][:filename].should == "foo.txt"
- params["people"][0]["files"][:tempfile].read.should == "bar\n"
- check params["foo"].should == ["1", "2"]
+ check expect(params["people"][0]["submit-name"]).to eq("Larry")
+ check expect(params["people"][0]["files"][:filename]).to eq("foo.txt")
+ expect(params["people"][0]["files"][:tempfile].read).to eq("bar\n")
+ check expect(params["foo"]).to eq(["1", "2"])
end
it "builds nested multipart bodies with an array of hashes" do
@@ -115,9 +115,9 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["files"][:filename].should == "foo.txt"
- params["files"][:tempfile].read.should == "bar\n"
- check params["foo"].should == [{"id" => "1", "name" => "Dave"}, {"id" => "2", "name" => "Steve"}]
+ check expect(params["files"][:filename]).to eq("foo.txt")
+ expect(params["files"][:tempfile].read).to eq("bar\n")
+ check expect(params["foo"]).to eq([{"id" => "1", "name" => "Dave"}, {"id" => "2", "name" => "Steve"}])
end
it "builds nested multipart bodies with arbitrarily nested array of hashes" do
@@ -133,11 +133,11 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["files"][:filename].should == "foo.txt"
- params["files"][:tempfile].read.should == "bar\n"
- check params["foo"].should == {"bar" => [{"id" => "1", "name" => "Dave"},
+ check expect(params["files"][:filename]).to eq("foo.txt")
+ expect(params["files"][:tempfile].read).to eq("bar\n")
+ check expect(params["foo"]).to eq({"bar" => [{"id" => "1", "name" => "Dave"},
{"id" => "2", "name" => "Steve", "qux" => [{"id" => '3', "name" => 'mike'},
- {"id" => '4', "name" => 'Joan'}]}]}
+ {"id" => '4', "name" => 'Joan'}]}]})
end
it 'does not break with params that look nested, but are not' do
@@ -151,10 +151,10 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["files"][0][:filename].should == "foo.txt"
- params["files"][0][:tempfile].read.should == "bar\n"
- check params["foo"][0].should == "1"
- check params["bar"][0].should == {"qux" => "2"}
+ check expect(params["files"][0][:filename]).to eq("foo.txt")
+ expect(params["files"][0][:tempfile].read).to eq("bar\n")
+ check expect(params["foo"][0]).to eq("1")
+ check expect(params["bar"][0]).to eq({"qux" => "2"})
end
it 'allows for nested files' do
@@ -169,21 +169,21 @@ describe Rack::Test::Utils do
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Utils::Multipart.parse_multipart(env)
- check params["foo"][0]["id"].should == "1"
- check params["foo"][0]["data"][:filename].should == "foo.txt"
- params["foo"][0]["data"][:tempfile].read.should == "bar\n"
- check params["foo"][1].should == {"id" => "2", "data" => ["3", "4"]}
+ check expect(params["foo"][0]["id"]).to eq("1")
+ check expect(params["foo"][0]["data"][:filename]).to eq("foo.txt")
+ expect(params["foo"][0]["data"][:tempfile].read).to eq("bar\n")
+ check expect(params["foo"][1]).to eq({"id" => "2", "data" => ["3", "4"]})
end
it "returns nil if no UploadedFiles were used" do
data = build_multipart("people" => [{"submit-name" => "Larry", "files" => "contents"}])
- data.should be_nil
+ expect(data).to be_nil
end
it "raises ArgumentErrors if params is not a Hash" do
- lambda {
+ expect {
build_multipart("foo=bar")
- }.should raise_error(ArgumentError, "value must be a Hash")
+ }.to raise_error(ArgumentError, "value must be a Hash")
end
def multipart_file(name)
diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb
index ba862b2..d0f019a 100644
--- a/spec/rack/test_spec.rb
+++ b/spec/rack/test_spec.rb
@@ -4,137 +4,137 @@ describe Rack::Test::Session do
describe "initialization" do
it "supports being initialized with a Rack::MockSession app" do
session = Rack::Test::Session.new(Rack::MockSession.new(app))
- session.request("/").should be_ok
+ expect(session.request("/")).to be_ok
end
it "supports being initialized with an app" do
session = Rack::Test::Session.new(app)
- session.request("/").should be_ok
+ expect(session.request("/")).to be_ok
end
end
describe "#request" do
it "requests the URI using GET by default" do
request "/"
- last_request.should be_get
- last_response.should be_ok
+ expect(last_request).to be_get
+ expect(last_response).to be_ok
end
it "returns a response" do
- request("/").should be_ok
+ expect(request("/")).to be_ok
end
it "uses the provided env" do
request "/", "X-Foo" => "bar"
- last_request.env["X-Foo"].should == "bar"
+ expect(last_request.env["X-Foo"]).to eq("bar")
end
it "allows HTTP_HOST to be set" do
request "/", "HTTP_HOST" => "www.example.ua"
- last_request.env['HTTP_HOST'].should == "www.example.ua"
+ expect(last_request.env['HTTP_HOST']).to eq("www.example.ua")
end
it "sets HTTP_HOST with port for non-default ports" do
request "http://foo.com:8080"
- last_request.env["HTTP_HOST"].should == "foo.com:8080"
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com:8080")
request "https://foo.com:8443"
- last_request.env["HTTP_HOST"].should == "foo.com:8443"
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com:8443")
end
it "sets HTTP_HOST without port for default ports" do
request "http://foo.com"
- last_request.env["HTTP_HOST"].should == "foo.com"
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
request "http://foo.com:80"
- last_request.env["HTTP_HOST"].should == "foo.com"
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
request "https://foo.com:443"
- last_request.env["HTTP_HOST"].should == "foo.com"
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
end
it "defaults to GET" do
request "/"
- last_request.env["REQUEST_METHOD"].should == "GET"
+ expect(last_request.env["REQUEST_METHOD"]).to eq("GET")
end
it "defaults the REMOTE_ADDR to 127.0.0.1" do
request "/"
- last_request.env["REMOTE_ADDR"].should == "127.0.0.1"
+ expect(last_request.env["REMOTE_ADDR"]).to eq("127.0.0.1")
end
it "sets rack.test to true in the env" do
request "/"
- last_request.env["rack.test"].should == true
+ expect(last_request.env["rack.test"]).to eq(true)
end
it "defaults to port 80" do
request "/"
- last_request.env["SERVER_PORT"].should == "80"
+ expect(last_request.env["SERVER_PORT"]).to eq("80")
end
it "defaults to example.org" do
request "/"
- last_request.env["SERVER_NAME"].should == "example.org"
+ expect(last_request.env["SERVER_NAME"]).to eq("example.org")
end
it "yields the response to a given block" do
request "/" do |response|
- response.should be_ok
+ expect(response).to be_ok
end
end
it "supports sending :params" do
request "/", :params => { "foo" => "bar" }
- last_request.GET["foo"].should == "bar"
+ expect(last_request.GET["foo"]).to eq("bar")
end
it "doesn't follow redirects by default" do
request "/redirect"
- last_response.should be_redirect
- last_response.body.should be_empty
+ expect(last_response).to be_redirect
+ expect(last_response.body).to be_empty
end
it "allows passing :input in for POSTs" do
request "/", :method => :post, :input => "foo"
- last_request.env["rack.input"].read.should == "foo"
+ expect(last_request.env["rack.input"].read).to eq("foo")
end
it "converts method names to a uppercase strings" do
request "/", :method => :put
- last_request.env["REQUEST_METHOD"].should == "PUT"
+ expect(last_request.env["REQUEST_METHOD"]).to eq("PUT")
end
it "prepends a slash to the URI path" do
request "foo"
- last_request.env["PATH_INFO"].should == "/foo"
+ expect(last_request.env["PATH_INFO"]).to eq("/foo")
end
it "accepts params and builds query strings for GET requests" do
request "/foo?baz=2", :params => {:foo => {:bar => "1"}}
- last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
+ expect(last_request.GET).to eq({ "baz" => "2", "foo" => { "bar" => "1" }})
end
it "parses query strings with repeated variable names correctly" do
request "/foo?bar=2&bar=3"
- last_request.GET.should == { "bar" => "3" }
+ expect(last_request.GET).to eq({ "bar" => "3" })
end
it "accepts raw input in params for GET requests" do
request "/foo?baz=2", :params => "foo[bar]=1"
- last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
+ expect(last_request.GET).to eq({ "baz" => "2", "foo" => { "bar" => "1" }})
end
it "does not rewrite a GET query string when :params is not supplied" do
request "/foo?a=1&b=2&c=3&e=4&d=5+%20"
- last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5+%20"
+ expect(last_request.query_string).to eq("a=1&b=2&c=3&e=4&d=5+%20")
end
it "accepts params and builds url encoded params for POST requests" do
request "/foo", :method => :post, :params => {:foo => {:bar => "1"}}
- last_request.env["rack.input"].read.should == "foo[bar]=1"
+ expect(last_request.env["rack.input"].read).to eq("foo[bar]=1")
end
it "accepts raw input in params for POST requests" do
request "/foo", :method => :post, :params => "foo[bar]=1"
- last_request.env["rack.input"].read.should == "foo[bar]=1"
+ expect(last_request.env["rack.input"].read).to eq("foo[bar]=1")
end
context "when the response body responds_to?(:close)" do
@@ -155,7 +155,7 @@ describe Rack::Test::Session do
it "closes response's body" do
body = CloseableBody.new
- body.should_receive(:close)
+ expect(body).to receive(:close)
app = lambda do |env|
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, body]
@@ -172,65 +172,65 @@ describe Rack::Test::Session do
session = Rack::Test::Session.new(Rack::MockSession.new(app))
session.request("/")
- session.last_response.body.should == "Hello, World!"
+ expect(session.last_response.body).to eq("Hello, World!")
end
end
context "when input is given" do
it "sends the input" do
request "/", :method => "POST", :input => "foo"
- last_request.env["rack.input"].read.should == "foo"
+ expect(last_request.env["rack.input"].read).to eq("foo")
end
it "does not send a multipart request" do
request "/", :method => "POST", :input => "foo"
- last_request.env["CONTENT_TYPE"].should_not == "application/x-www-form-urlencoded"
+ expect(last_request.env["CONTENT_TYPE"]).not_to eq("application/x-www-form-urlencoded")
end
end
context "for a POST specified with :method" do
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
request "/", :method => "POST"
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
end
end
context "for a POST specified with REQUEST_METHOD" do
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
request "/", "REQUEST_METHOD" => "POST"
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
end
end
context "when CONTENT_TYPE is specified in the env" do
it "does not overwrite the CONTENT_TYPE" do
request "/", "CONTENT_TYPE" => "application/xml"
- last_request.env["CONTENT_TYPE"].should == "application/xml"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/xml")
end
end
context "when the URL is https://" do
it "sets rack.url_scheme to https" do
get "https://example.org/"
- last_request.env["rack.url_scheme"].should == "https"
+ expect(last_request.env["rack.url_scheme"]).to eq("https")
end
it "sets SERVER_PORT to 443" do
get "https://example.org/"
- last_request.env["SERVER_PORT"].should == "443"
+ expect(last_request.env["SERVER_PORT"]).to eq("443")
end
it "sets HTTPS to on" do
get "https://example.org/"
- last_request.env["HTTPS"].should == "on"
+ expect(last_request.env["HTTPS"]).to eq("on")
end
end
context "for a XHR" do
it "sends XMLHttpRequest for the X-Requested-With header" do
request "/", :xhr => true
- last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
- last_request.should be_xhr
+ expect(last_request.env["HTTP_X_REQUESTED_WITH"]).to eq("XMLHttpRequest")
+ expect(last_request).to be_xhr
end
end
end
@@ -240,21 +240,21 @@ describe Rack::Test::Session do
header "User-Agent", "Firefox"
request "/"
- last_request.env["HTTP_USER_AGENT"].should == "Firefox"
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Firefox")
end
it "sets a Content-Type to be sent with requests" do
header "Content-Type", "application/json"
request "/"
- last_request.env["CONTENT_TYPE"].should == "application/json"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/json")
end
it "sets a Host to be sent with requests" do
header "Host", "www.example.ua"
request "/"
- last_request.env["HTTP_HOST"].should == "www.example.ua"
+ expect(last_request.env["HTTP_HOST"]).to eq("www.example.ua")
end
it "persists across multiple requests" do
@@ -262,7 +262,7 @@ describe Rack::Test::Session do
request "/"
request "/"
- last_request.env["HTTP_USER_AGENT"].should == "Firefox"
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Firefox")
end
it "overwrites previously set headers" do
@@ -270,7 +270,7 @@ describe Rack::Test::Session do
header "User-Agent", "Safari"
request "/"
- last_request.env["HTTP_USER_AGENT"].should == "Safari"
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Safari")
end
it "can be used to clear a header" do
@@ -278,14 +278,14 @@ describe Rack::Test::Session do
header "User-Agent", nil
request "/"
- last_request.env.should_not have_key("HTTP_USER_AGENT")
+ expect(last_request.env).not_to have_key("HTTP_USER_AGENT")
end
it "is overridden by headers sent during the request" do
header "User-Agent", "Firefox"
request "/", "HTTP_USER_AGENT" => "Safari"
- last_request.env["HTTP_USER_AGENT"].should == "Safari"
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Safari")
end
end
@@ -294,7 +294,7 @@ describe Rack::Test::Session do
env "rack.session", {:csrf => 'token'}
request "/"
- last_request.env["rack.session"].should == {:csrf => 'token'}
+ expect(last_request.env["rack.session"]).to eq({:csrf => 'token'})
end
it "persists across multiple requests" do
@@ -302,7 +302,7 @@ describe Rack::Test::Session do
request "/"
request "/"
- last_request.env["rack.session"].should == {:csrf => 'token'}
+ expect(last_request.env["rack.session"]).to eq({:csrf => 'token'})
end
it "overwrites previously set envs" do
@@ -310,7 +310,7 @@ describe Rack::Test::Session do
env "rack.session", {:some => :thing}
request "/"
- last_request.env["rack.session"].should == {:some => :thing}
+ expect(last_request.env["rack.session"]).to eq({:some => :thing})
end
it "can be used to clear a env" do
@@ -318,14 +318,14 @@ describe Rack::Test::Session do
env "rack.session", nil
request "/"
- last_request.env.should_not have_key("X_CSRF_TOKEN")
+ expect(last_request.env).not_to have_key("X_CSRF_TOKEN")
end
it "is overridden by envs sent during the request" do
env "rack.session", {:csrf => 'token'}
request "/", "rack.session" => {:some => :thing}
- last_request.env["rack.session"].should == {:some => :thing}
+ expect(last_request.env["rack.session"]).to eq({:some => :thing})
end
end
@@ -334,7 +334,7 @@ describe Rack::Test::Session do
authorize "bryan", "secret"
request "/"
- last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
+ expect(last_request.env["HTTP_AUTHORIZATION"]).to eq("Basic YnJ5YW46c2VjcmV0\n")
end
it "includes the header for subsequent requests" do
@@ -342,7 +342,7 @@ describe Rack::Test::Session do
request "/"
request "/"
- last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
+ expect(last_request.env["HTTP_AUTHORIZATION"]).to eq("Basic YnJ5YW46c2VjcmV0\n")
end
end
@@ -351,56 +351,56 @@ describe Rack::Test::Session do
get "/redirect"
follow_redirect!
- last_response.should_not be_redirect
- last_response.body.should == "You've been redirected"
- last_request.env["HTTP_REFERER"].should eql("http://example.org/redirect")
+ expect(last_response).not_to be_redirect
+ expect(last_response.body).to eq("You've been redirected")
+ expect(last_request.env["HTTP_REFERER"]).to eql("http://example.org/redirect")
end
it "does not include params when following the redirect" do
get "/redirect", { "foo" => "bar" }
follow_redirect!
- last_request.GET.should == {}
+ expect(last_request.GET).to eq({})
end
it "raises an error if the last_response is not set" do
- lambda {
+ expect {
follow_redirect!
- }.should raise_error(Rack::Test::Error)
+ }.to raise_error(Rack::Test::Error)
end
it "raises an error if the last_response is not a redirect" do
get "/"
- lambda {
+ expect {
follow_redirect!
- }.should raise_error(Rack::Test::Error)
+ }.to raise_error(Rack::Test::Error)
end
end
describe "#last_request" do
it "returns the most recent request" do
request "/"
- last_request.env["PATH_INFO"].should == "/"
+ expect(last_request.env["PATH_INFO"]).to eq("/")
end
it "raises an error if no requests have been issued" do
- lambda {
+ expect {
last_request
- }.should raise_error(Rack::Test::Error)
+ }.to raise_error(Rack::Test::Error)
end
end
describe "#last_response" do
it "returns the most recent response" do
request "/"
- last_response["Content-Type"].should == "text/html;charset=utf-8"
+ expect(last_response["Content-Type"]).to eq("text/html;charset=utf-8")
end
it "raises an error if no requests have been issued" do
- lambda {
+ expect {
last_response
- }.should raise_error
+ }.to raise_error(Rack::Test::Error)
end
end
@@ -413,7 +413,7 @@ describe Rack::Test::Session do
end
get "/"
- ran.should == true
+ expect(ran).to eq(true)
end
it "runs multiple callbacks" do
@@ -426,7 +426,7 @@ describe Rack::Test::Session do
end
get "/"
- count.should == 2
+ expect(count).to eq(2)
end
end
@@ -439,27 +439,27 @@ describe Rack::Test::Session do
it "uses the provided params hash" do
get "/", :foo => "bar"
- last_request.GET.should == { "foo" => "bar" }
+ expect(last_request.GET).to eq({ "foo" => "bar" })
end
it "sends params with parens in names" do
get "/", "foo(1i)" => "bar"
- last_request.GET["foo(1i)"].should == "bar"
+ expect(last_request.GET["foo(1i)"]).to eq("bar")
end
it "supports params with encoding sensitive names" do
get "/", "foo bar" => "baz"
- last_request.GET["foo bar"].should == "baz"
+ expect(last_request.GET["foo bar"]).to eq("baz")
end
it "supports params with nested encoding sensitive names" do
get "/", "boo" => {"foo bar" => "baz"}
- last_request.GET.should == {"boo" => {"foo bar" => "baz"}}
+ expect(last_request.GET).to eq({"boo" => {"foo bar" => "baz"}})
end
it "accepts params in the path" do
get "/?foo=bar"
- last_request.GET.should == { "foo" => "bar" }
+ expect(last_request.GET).to eq({ "foo" => "bar" })
end
end
@@ -480,28 +480,28 @@ describe Rack::Test::Session do
it "uses the provided params hash" do
post "/", :foo => "bar"
- last_request.POST.should == { "foo" => "bar" }
+ expect(last_request.POST).to eq({ "foo" => "bar" })
end
it "supports params with encoding sensitive names" do
post "/", "foo bar" => "baz"
- last_request.POST["foo bar"].should == "baz"
+ expect(last_request.POST["foo bar"]).to eq("baz")
end
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
post "/"
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
end
it "accepts a body" do
post "/", "Lobsterlicious!"
- last_request.body.read.should == "Lobsterlicious!"
+ expect(last_request.body.read).to eq("Lobsterlicious!")
end
context "when CONTENT_TYPE is specified in the env" do
it "does not overwrite the CONTENT_TYPE" do
post "/", {}, { "CONTENT_TYPE" => "application/xml" }
- last_request.env["CONTENT_TYPE"].should == "application/xml"
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/xml")
end
end
end
@@ -515,7 +515,7 @@ describe Rack::Test::Session do
it "accepts a body" do
put "/", "Lobsterlicious!"
- last_request.body.read.should == "Lobsterlicious!"
+ expect(last_request.body.read).to eq("Lobsterlicious!")
end
end
@@ -528,7 +528,7 @@ describe Rack::Test::Session do
it "accepts a body" do
patch "/", "Lobsterlicious!"
- last_request.body.read.should == "Lobsterlicious!"
+ expect(last_request.body.read).to eq("Lobsterlicious!")
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 0375aef..0c0af1e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -26,41 +26,41 @@ shared_examples_for "any #verb methods" do
it "requests the URL using VERB" do
send(verb, "/")
- check last_request.env["REQUEST_METHOD"].should == verb.upcase
- last_response.should be_ok
+ check expect(last_request.env["REQUEST_METHOD"]).to eq(verb.upcase)
+ expect(last_response).to be_ok
end
it "uses the provided env" do
send(verb, "/", {}, { "HTTP_USER_AGENT" => "Rack::Test" })
- last_request.env["HTTP_USER_AGENT"].should == "Rack::Test"
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Rack::Test")
end
it "yields the response to a given block" do
yielded = false
send(verb, "/") do |response|
- response.should be_ok
+ expect(response).to be_ok
yielded = true
end
- yielded.should be_true
+ expect(yielded).to be_truthy
end
it "sets the HTTP_HOST header with port" do
send(verb, "http://example.org:8080/uri")
- last_request.env["HTTP_HOST"].should == "example.org:8080"
+ expect(last_request.env["HTTP_HOST"]).to eq("example.org:8080")
end
it "sets the HTTP_HOST header without port" do
send(verb, "/uri")
- last_request.env["HTTP_HOST"].should == "example.org"
+ expect(last_request.env["HTTP_HOST"]).to eq("example.org")
end
context "for a XHR" do
it "sends XMLHttpRequest for the X-Requested-With header" do
send(verb, "/", {}, { :xhr => true })
- last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
- last_request.should be_xhr
+ expect(last_request.env["HTTP_X_REQUESTED_WITH"]).to eq("XMLHttpRequest")
+ expect(last_request).to be_xhr
end
end
end
diff --git a/spec/support/matchers/body.rb b/spec/support/matchers/body.rb
index 0c83348..a79c1ff 100644
--- a/spec/support/matchers/body.rb
+++ b/spec/support/matchers/body.rb
@@ -1,6 +1,6 @@
RSpec::Matchers.define :have_body do |expected|
match do |response|
- response.body.should == expected
+ expect(response.body).to eq(expected)
end
description do
|