webmock 1.3.5 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe Util::HashCounter do
3
+ describe WebMock::Util::HashCounter do
4
4
 
5
5
  it "should return 0 for non existing key" do
6
- Util::HashCounter.new.get(:abc).should == 0
6
+ WebMock::Util::HashCounter.new.get(:abc).should == 0
7
7
  end
8
8
 
9
9
  it "should increase the returned value on every put with the same key" do
10
- counter =Util::HashCounter.new
10
+ counter = WebMock::Util::HashCounter.new
11
11
  counter.put(:abc)
12
12
  counter.get(:abc).should == 1
13
13
  counter.put(:abc)
@@ -15,7 +15,7 @@ describe Util::HashCounter do
15
15
  end
16
16
 
17
17
  it "should only increase value for given key provided to put" do
18
- counter =Util::HashCounter.new
18
+ counter = WebMock::Util::HashCounter.new
19
19
  counter.put(:abc)
20
20
  counter.get(:abc).should == 1
21
21
  counter.get(:def).should == 0
@@ -4,22 +4,22 @@ describe WebMock::Util::Headers do
4
4
 
5
5
  it "should decode_userinfo_from_header handles basic auth" do
6
6
  authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
7
- userinfo = Util::Headers.decode_userinfo_from_header(authorization_header)
7
+ userinfo = WebMock::Util::Headers.decode_userinfo_from_header(authorization_header)
8
8
  userinfo.should == "username:secret"
9
9
  end
10
10
 
11
11
  describe "sorted_headers_string" do
12
12
 
13
13
  it "should return nice string for hash with string values" do
14
- Util::Headers.sorted_headers_string({"a" => "b"}).should == "{'A'=>'b'}"
14
+ WebMock::Util::Headers.sorted_headers_string({"a" => "b"}).should == "{'A'=>'b'}"
15
15
  end
16
16
 
17
17
  it "should return nice string for hash with array values" do
18
- Util::Headers.sorted_headers_string({"a" => ["b", "c"]}).should == "{'A'=>['b', 'c']}"
18
+ WebMock::Util::Headers.sorted_headers_string({"a" => ["b", "c"]}).should == "{'A'=>['b', 'c']}"
19
19
  end
20
20
 
21
21
  it "should return nice string for hash with array values and string values" do
22
- Util::Headers.sorted_headers_string({"a" => ["b", "c"], "d" => "e"}).should == "{'A'=>['b', 'c'], 'D'=>'e'}"
22
+ WebMock::Util::Headers.sorted_headers_string({"a" => ["b", "c"], "d" => "e"}).should == "{'A'=>['b', 'c'], 'D'=>'e'}"
23
23
  end
24
24
 
25
25
 
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  unless defined? SAMPLE_HEADERS
4
4
  SAMPLE_HEADERS = { "Content-Length" => "8888", "Accept" => "application/json" }
5
- ESCAPED_PARAMS = "x=ab%2Bc&z=%27Stop%21%27%20said%20Fred"
5
+ ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred"
6
6
  NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
7
7
  WWW_EXAMPLE_COM_CONTENT_LENGTH = 596
8
8
  end
@@ -21,7 +21,7 @@ end
21
21
  describe "WebMock", :shared => true do
22
22
  before(:each) do
23
23
  WebMock.disable_net_connect!
24
- RequestRegistry.instance.reset_webmock
24
+ WebMock::RequestRegistry.instance.reset_webmock
25
25
  end
26
26
 
27
27
  describe "when web connect" do
@@ -98,6 +98,12 @@ describe "WebMock", :shared => true do
98
98
  http_request(:get, "http://127.0.0.1:12345/")
99
99
  }.should raise_error(connection_refused_exception_class)
100
100
  end
101
+
102
+ it "should allow a real request to 0.0.0.0" do
103
+ lambda {
104
+ http_request(:get, "http://0.0.0.0:12345/")
105
+ }.should raise_error(connection_refused_exception_class)
106
+ end
101
107
  end
102
108
 
103
109
  describe "is not allowed with exception for allowed domains" do
@@ -116,7 +122,7 @@ describe "WebMock", :shared => true do
116
122
  }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
117
123
  end
118
124
 
119
- it "should allow a real request to cms.local" do
125
+ it "should allow a real request to allowed host" do
120
126
  http_request(:get, "http://www.example.org/").status.should == "200"
121
127
  end
122
128
  end
@@ -833,76 +839,83 @@ describe "WebMock", :shared => true do
833
839
  it "should pass if request was executed with the same uri and method" do
834
840
  lambda {
835
841
  http_request(:get, "http://www.example.com/")
836
- request(:get, "http://www.example.com").should have_been_made.once
842
+ a_request(:get, "http://www.example.com").should have_been_made.once
843
+ }.should_not raise_error
844
+ end
845
+
846
+ it "should accept verification as WebMock class method invocation" do
847
+ lambda {
848
+ http_request(:get, "http://www.example.com/")
849
+ WebMock.request(:get, "http://www.example.com").should have_been_made.once
837
850
  }.should_not raise_error
838
851
  end
839
852
 
840
853
  it "should pass if request was not expected and not executed" do
841
854
  lambda {
842
- request(:get, "http://www.example.com").should_not have_been_made
855
+ a_request(:get, "http://www.example.com").should_not have_been_made
843
856
  }.should_not raise_error
844
857
  end
845
858
 
846
859
  it "should fail if request was not expected but executed" do
847
860
  lambda {
848
861
  http_request(:get, "http://www.example.com/")
849
- request(:get, "http://www.example.com").should_not have_been_made
862
+ a_request(:get, "http://www.example.com").should_not have_been_made
850
863
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
851
864
  end
852
865
 
853
866
 
854
867
  it "should fail if request was not executed" do
855
868
  lambda {
856
- request(:get, "http://www.example.com").should have_been_made
869
+ a_request(:get, "http://www.example.com").should have_been_made
857
870
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
858
871
  end
859
872
 
860
873
  it "should fail if request was executed to different uri" do
861
874
  lambda {
862
875
  http_request(:get, "http://www.example.com/")
863
- request(:get, "http://www.example.org").should have_been_made
876
+ a_request(:get, "http://www.example.org").should have_been_made
864
877
  }.should fail_with("The request GET http://www.example.org/ was expected to execute 1 time but it executed 0 times")
865
878
  end
866
879
 
867
880
  it "should fail if request was executed with different method" do
868
881
  lambda {
869
882
  http_request(:post, "http://www.example.com/", :body => "abc")
870
- request(:get, "http://www.example.com").should have_been_made
883
+ a_request(:get, "http://www.example.com").should have_been_made
871
884
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
872
885
  end
873
886
 
874
887
  it "should pass if request was executed with different form of uri" do
875
888
  lambda {
876
889
  http_request(:get, "http://www.example.com/")
877
- request(:get, "www.example.com").should have_been_made
890
+ a_request(:get, "www.example.com").should have_been_made
878
891
  }.should_not raise_error
879
892
  end
880
893
 
881
894
  it "should pass if request was executed with different form of uri without port " do
882
895
  lambda {
883
896
  http_request(:get, "http://www.example.com/")
884
- request(:get, "www.example.com:80").should have_been_made
897
+ a_request(:get, "www.example.com:80").should have_been_made
885
898
  }.should_not raise_error
886
899
  end
887
900
 
888
901
  it "should pass if request was executed with different form of uri with port" do
889
902
  lambda {
890
903
  http_request(:get, "http://www.example.com/")
891
- request(:get, "www.example.com:80").should have_been_made
904
+ a_request(:get, "www.example.com:80").should have_been_made
892
905
  }.should_not raise_error
893
906
  end
894
907
 
895
908
  it "should fail if request was executed with different port" do
896
909
  lambda {
897
910
  http_request(:get, "http://www.example.com:80/")
898
- request(:get, "www.example.com:90").should have_been_made
911
+ a_request(:get, "www.example.com:90").should have_been_made
899
912
  }.should fail_with("The request GET http://www.example.com:90/ was expected to execute 1 time but it executed 0 times")
900
913
  end
901
914
 
902
915
  it "should pass if request was executed with different form of uri with https port" do
903
916
  lambda {
904
917
  http_request(:get, "https://www.example.com/")
905
- request(:get, "https://www.example.com:443/").should have_been_made
918
+ a_request(:get, "https://www.example.com:443/").should have_been_made
906
919
  }.should_not raise_error
907
920
  end
908
921
 
@@ -916,21 +929,21 @@ describe "WebMock", :shared => true do
916
929
  it "should pass if request was executed with escaped params" do
917
930
  lambda {
918
931
  http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}")
919
- request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}").should have_been_made
932
+ a_request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}").should have_been_made
920
933
  }.should_not raise_error
921
934
  end
922
935
 
923
936
  it "should pass if request was executed with non escaped params but escaped expected" do
924
937
  lambda {
925
938
  http_request(:get, "http://www.example.com/?#{NOT_ESCAPED_PARAMS}")
926
- request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").should have_been_made
939
+ a_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}").should have_been_made
927
940
  }.should_not raise_error
928
941
  end
929
942
 
930
943
  it "should pass if request was executed with escaped params but uri matichg regexp expected" do
931
944
  lambda {
932
945
  http_request(:get, "http://www.example.com/?#{ESCAPED_PARAMS}")
933
- request(:get, /.*example.*/).should have_been_made
946
+ a_request(:get, /.*example.*/).should have_been_made
934
947
  }.should_not raise_error
935
948
  end
936
949
 
@@ -944,21 +957,21 @@ describe "WebMock", :shared => true do
944
957
  it "should pass if the request was executed with query params declared in a hash in query option" do
945
958
  lambda {
946
959
  http_request(:get, "http://www.example.com/?a[]=b&a[]=c")
947
- request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
960
+ a_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
948
961
  }.should_not raise_error
949
962
  end
950
963
 
951
964
  it "should pass if the request was executed with query params declared as string in query option" do
952
965
  lambda {
953
966
  http_request(:get, "http://www.example.com/?a[]=b&a[]=c")
954
- request(:get, "www.example.com").with(:query => "a[]=b&a[]=c").should have_been_made
967
+ a_request(:get, "www.example.com").with(:query => "a[]=b&a[]=c").should have_been_made
955
968
  }.should_not raise_error
956
969
  end
957
970
 
958
971
  it "should pass if the request was executed with query params both in uri and in query option" do
959
972
  lambda {
960
973
  http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c")
961
- request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]}).should have_been_made
974
+ a_request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]}).should have_been_made
962
975
  }.should_not raise_error
963
976
  end
964
977
 
@@ -968,35 +981,35 @@ describe "WebMock", :shared => true do
968
981
  lambda {
969
982
  http_request(:get, "http://www.example.com/")
970
983
  http_request(:get, "http://www.example.com/")
971
- request(:get, "http://www.example.com").should have_been_made
984
+ a_request(:get, "http://www.example.com").should have_been_made
972
985
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 2 times")
973
986
  end
974
987
 
975
988
  it "should fail if requested less times than expected" do
976
989
  lambda {
977
990
  http_request(:get, "http://www.example.com/")
978
- request(:get, "http://www.example.com").should have_been_made.twice
991
+ a_request(:get, "http://www.example.com").should have_been_made.twice
979
992
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 2 times but it executed 1 time")
980
993
  end
981
994
 
982
995
  it "should fail if requested less times than expected when 3 times expected" do
983
996
  lambda {
984
997
  http_request(:get, "http://www.example.com/")
985
- request(:get, "http://www.example.com").should have_been_made.times(3)
998
+ a_request(:get, "http://www.example.com").should have_been_made.times(3)
986
999
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 3 times but it executed 1 time")
987
1000
  end
988
1001
 
989
1002
  it "should succeed if request was executed with the same body" do
990
1003
  lambda {
991
1004
  http_request(:post, "http://www.example.com/", :body => "abc")
992
- request(:post, "www.example.com").with(:body => "abc").should have_been_made
1005
+ a_request(:post, "www.example.com").with(:body => "abc").should have_been_made
993
1006
  }.should_not raise_error
994
1007
  end
995
1008
 
996
1009
  it "should fail if request was executed with different body" do
997
1010
  lambda {
998
1011
  http_request(:get, "http://www.example.com/", :body => "abc")
999
- request(:get, "www.example.com").
1012
+ a_request(:get, "www.example.com").
1000
1013
  with(:body => "def").should have_been_made
1001
1014
  }.should fail_with('The request GET http://www.example.com/ with body "def" was expected to execute 1 time but it executed 0 times')
1002
1015
  end
@@ -1006,14 +1019,14 @@ describe "WebMock", :shared => true do
1006
1019
  it "should succeed if request was executed with the same body" do
1007
1020
  lambda {
1008
1021
  http_request(:post, "http://www.example.com/", :body => "abc")
1009
- request(:post, "www.example.com").with(:body => /^abc$/).should have_been_made
1022
+ a_request(:post, "www.example.com").with(:body => /^abc$/).should have_been_made
1010
1023
  }.should_not raise_error
1011
1024
  end
1012
1025
 
1013
1026
  it "should fail if request was executed with different body" do
1014
1027
  lambda {
1015
1028
  http_request(:get, "http://www.example.com/", :body => /^abc/)
1016
- request(:get, "www.example.com").
1029
+ a_request(:get, "www.example.com").
1017
1030
  with(:body => "xabc").should have_been_made
1018
1031
  }.should fail_with('The request GET http://www.example.com/ with body "xabc" was expected to execute 1 time but it executed 0 times')
1019
1032
  end
@@ -1029,21 +1042,21 @@ describe "WebMock", :shared => true do
1029
1042
  it "should succeed" do
1030
1043
  lambda {
1031
1044
  http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&c[d][]=f&b=five')
1032
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1045
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1033
1046
  }.should_not raise_error
1034
1047
  end
1035
1048
 
1036
1049
  it "should succeed if url encoded params have different order" do
1037
1050
  lambda {
1038
1051
  http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&b=five&c[d][]=f')
1039
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1052
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1040
1053
  }.should_not raise_error
1041
1054
  end
1042
1055
 
1043
1056
  it "should fail if request is executed with url encoded body not matching hash" do
1044
1057
  lambda {
1045
1058
  http_request(:post, "http://www.example.com/", :body => 'c[d][]=f&a=1&c[d][]=e')
1046
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1059
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1047
1060
  }.should fail_with(fail_message)
1048
1061
  end
1049
1062
 
@@ -1055,7 +1068,7 @@ describe "WebMock", :shared => true do
1055
1068
  lambda {
1056
1069
  http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
1057
1070
  :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}")
1058
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1071
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1059
1072
  }.should_not raise_error
1060
1073
  end
1061
1074
 
@@ -1063,7 +1076,7 @@ describe "WebMock", :shared => true do
1063
1076
  lambda {
1064
1077
  http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
1065
1078
  :body => "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}")
1066
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1079
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1067
1080
  }.should_not raise_error
1068
1081
  end
1069
1082
 
@@ -1077,7 +1090,7 @@ describe "WebMock", :shared => true do
1077
1090
  lambda {
1078
1091
  http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
1079
1092
  :body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
1080
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1093
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1081
1094
  }.should_not raise_error
1082
1095
  end
1083
1096
 
@@ -1085,7 +1098,7 @@ describe "WebMock", :shared => true do
1085
1098
  lambda {
1086
1099
  http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
1087
1100
  :body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n")
1088
- request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1101
+ a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made
1089
1102
  }.should_not raise_error
1090
1103
  end
1091
1104
 
@@ -1096,7 +1109,7 @@ describe "WebMock", :shared => true do
1096
1109
  it "should succeed if request was executed with the same headers" do
1097
1110
  lambda {
1098
1111
  http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
1099
- request(:get, "www.example.com").
1112
+ a_request(:get, "www.example.com").
1100
1113
  with(:headers => SAMPLE_HEADERS).should have_been_made
1101
1114
  }.should_not raise_error
1102
1115
  end
@@ -1104,7 +1117,7 @@ describe "WebMock", :shared => true do
1104
1117
  it "should succeed if request was executed with the same headers with value declared as array" do
1105
1118
  lambda {
1106
1119
  http_request(:get, "http://www.example.com/", :headers => {"a" => "b"})
1107
- request(:get, "www.example.com").
1120
+ a_request(:get, "www.example.com").
1108
1121
  with(:headers => {"a" => ["b"]}).should have_been_made
1109
1122
  }.should_not raise_error
1110
1123
  end
@@ -1114,7 +1127,7 @@ describe "WebMock", :shared => true do
1114
1127
  it "should succeed if request was executed with the same headers" do
1115
1128
  lambda {
1116
1129
  http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
1117
- request(:get, "www.example.com").
1130
+ a_request(:get, "www.example.com").
1118
1131
  with(:headers => {"a" => ["b", "c"]}).should have_been_made
1119
1132
  }.should_not raise_error
1120
1133
  end
@@ -1122,7 +1135,7 @@ describe "WebMock", :shared => true do
1122
1135
  it "should succeed if request was executed with the same headers but different order" do
1123
1136
  lambda {
1124
1137
  http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
1125
- request(:get, "www.example.com").
1138
+ a_request(:get, "www.example.com").
1126
1139
  with(:headers => {"a" => ["c", "b"]}).should have_been_made
1127
1140
  }.should_not raise_error
1128
1141
  end
@@ -1130,7 +1143,7 @@ describe "WebMock", :shared => true do
1130
1143
  it "should fail if request was executed with different headers" do
1131
1144
  lambda {
1132
1145
  http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]})
1133
- request(:get, "www.example.com").
1146
+ a_request(:get, "www.example.com").
1134
1147
  with(:headers => {"a" => ["b", "d"]}).should have_been_made
1135
1148
  }.should fail_with("The request GET http://www.example.com/ with headers {'A'=>['b', 'd']} was expected to execute 1 time but it executed 0 times")
1136
1149
  end
@@ -1140,7 +1153,7 @@ describe "WebMock", :shared => true do
1140
1153
  it "should fail if request was executed with different headers" do
1141
1154
  lambda {
1142
1155
  http_request(:get, "http://www.example.com/", :headers => SAMPLE_HEADERS)
1143
- request(:get, "www.example.com").
1156
+ a_request(:get, "www.example.com").
1144
1157
  with(:headers => { 'Content-Length' => '9999'}).should have_been_made
1145
1158
  }.should fail_with("The request GET http://www.example.com/ with headers {'Content-Length'=>'9999'} was expected to execute 1 time but it executed 0 times")
1146
1159
  end
@@ -1148,7 +1161,7 @@ describe "WebMock", :shared => true do
1148
1161
  it "should fail if request was executed with less headers" do
1149
1162
  lambda {
1150
1163
  http_request(:get, "http://www.example.com/", :headers => {'A' => 'a'})
1151
- request(:get, "www.example.com").
1164
+ a_request(:get, "www.example.com").
1152
1165
  with(:headers => {'A' => 'a', 'B' => 'b'}).should have_been_made
1153
1166
  }.should fail_with("The request GET http://www.example.com/ with headers {'A'=>'a', 'B'=>'b'} was expected to execute 1 time but it executed 0 times")
1154
1167
  end
@@ -1158,7 +1171,7 @@ describe "WebMock", :shared => true do
1158
1171
  http_request(:get, "http://www.example.com/",
1159
1172
  :headers => {'A' => 'a', 'B' => 'b'}
1160
1173
  )
1161
- request(:get, "www.example.com").
1174
+ a_request(:get, "www.example.com").
1162
1175
  with(:headers => {'A' => 'a'}).should have_been_made
1163
1176
  }.should_not raise_error
1164
1177
  end
@@ -1169,14 +1182,14 @@ describe "WebMock", :shared => true do
1169
1182
  :body => "abc",
1170
1183
  :headers => SAMPLE_HEADERS
1171
1184
  )
1172
- request(:get, "www.example.com").should have_been_made
1185
+ a_request(:get, "www.example.com").should have_been_made
1173
1186
  }.should_not raise_error
1174
1187
  end
1175
1188
 
1176
1189
  it "should succeed if request was executed with headers matching regular expressions" do
1177
1190
  lambda {
1178
1191
  http_request(:get, "http://www.example.com/", :headers => { 'user-agent' => 'MyAppName' })
1179
- request(:get, "www.example.com").
1192
+ a_request(:get, "www.example.com").
1180
1193
  with(:headers => { :user_agent => /^MyAppName$/ }).should have_been_made
1181
1194
  }.should_not raise_error
1182
1195
  end
@@ -1184,7 +1197,7 @@ describe "WebMock", :shared => true do
1184
1197
  it "should fail if request was executed with headers not matching regular expression" do
1185
1198
  lambda {
1186
1199
  http_request(:get, "http://www.example.com/", :headers => { 'user_agent' => 'xMyAppName' })
1187
- request(:get, "www.example.com").
1200
+ a_request(:get, "www.example.com").
1188
1201
  with(:headers => { :user_agent => /^MyAppName$/ }).should have_been_made
1189
1202
  }.should fail_with("The request GET http://www.example.com/ with headers {'User-Agent'=>/^MyAppName$/} was expected to execute 1 time but it executed 0 times")
1190
1203
  end
@@ -1192,21 +1205,21 @@ describe "WebMock", :shared => true do
1192
1205
  it "should suceed if request was executed and block evaluated to true" do
1193
1206
  lambda {
1194
1207
  http_request(:post, "http://www.example.com/", :body => "wadus")
1195
- request(:post, "www.example.com").with { |req| req.body == "wadus" }.should have_been_made
1208
+ a_request(:post, "www.example.com").with { |req| req.body == "wadus" }.should have_been_made
1196
1209
  }.should_not raise_error
1197
1210
  end
1198
1211
 
1199
1212
  it "should fail if request was executed and block evaluated to false" do
1200
1213
  lambda {
1201
1214
  http_request(:post, "http://www.example.com/", :body => "abc")
1202
- request(:post, "www.example.com").with { |req| req.body == "wadus" }.should have_been_made
1215
+ a_request(:post, "www.example.com").with { |req| req.body == "wadus" }.should have_been_made
1203
1216
  }.should fail_with("The request POST http://www.example.com/ with given block was expected to execute 1 time but it executed 0 times")
1204
1217
  end
1205
1218
 
1206
1219
  it "should fail if request was not expected but it executed and block matched request" do
1207
1220
  lambda {
1208
1221
  http_request(:post, "http://www.example.com/", :body => "wadus")
1209
- request(:post, "www.example.com").with { |req| req.body == "wadus" }.should_not have_been_made
1222
+ a_request(:post, "www.example.com").with { |req| req.body == "wadus" }.should_not have_been_made
1210
1223
  }.should fail_with("The request POST http://www.example.com/ with given block was expected to execute 0 times but it executed 1 time")
1211
1224
  end
1212
1225
 
@@ -1219,28 +1232,28 @@ describe "WebMock", :shared => true do
1219
1232
  it "should succeed if succeed if request was executed with expected credentials" do
1220
1233
  lambda {
1221
1234
  http_request(:get, "http://user:pass@www.example.com/")
1222
- request(:get, "http://user:pass@www.example.com").should have_been_made.once
1235
+ a_request(:get, "http://user:pass@www.example.com").should have_been_made.once
1223
1236
  }.should_not raise_error
1224
1237
  end
1225
1238
 
1226
1239
  it "should fail if request was executed with different credentials than expected" do
1227
1240
  lambda {
1228
1241
  http_request(:get, "http://user:pass@www.example.com/")
1229
- request(:get, "http://user:pazz@www.example.com").should have_been_made.once
1242
+ a_request(:get, "http://user:pazz@www.example.com").should have_been_made.once
1230
1243
  }.should fail_with("The request GET http://user:pazz@www.example.com/ was expected to execute 1 time but it executed 0 times")
1231
1244
  end
1232
1245
 
1233
1246
  it "should fail if request was executed without credentials but credentials were expected" do
1234
1247
  lambda {
1235
1248
  http_request(:get, "http://www.example.com/")
1236
- request(:get, "http://user:pass@www.example.com").should have_been_made.once
1249
+ a_request(:get, "http://user:pass@www.example.com").should have_been_made.once
1237
1250
  }.should fail_with("The request GET http://user:pass@www.example.com/ was expected to execute 1 time but it executed 0 times")
1238
1251
  end
1239
1252
 
1240
1253
  it "should fail if request was executed with credentials but expected without" do
1241
1254
  lambda {
1242
1255
  http_request(:get, "http://user:pass@www.example.com/")
1243
- request(:get, "http://www.example.com").should have_been_made.once
1256
+ a_request(:get, "http://www.example.com").should have_been_made.once
1244
1257
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times")
1245
1258
  end
1246
1259
 
@@ -1358,14 +1371,14 @@ describe "WebMock", :shared => true do
1358
1371
  setup_expectations_for_real_example_com_request
1359
1372
  lambda {
1360
1373
  http_request(:get, "http://www.example.com/")
1361
- request(:get, "http://www.example.com").should have_been_made
1374
+ a_request(:get, "http://www.example.com").should have_been_made
1362
1375
  }.should_not raise_error
1363
1376
  end
1364
1377
 
1365
1378
  it "should verify that non expected requests didn't occur" do
1366
1379
  lambda {
1367
1380
  http_request(:get, "http://www.example.com/")
1368
- request(:get, "http://www.example.com").should_not have_been_made
1381
+ a_request(:get, "http://www.example.com").should_not have_been_made
1369
1382
  }.should fail_with("The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time")
1370
1383
  end
1371
1384
  end