webmock 1.20.3 → 1.20.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +21 -22
  3. data/lib/webmock/matchers/hash_including_matcher.rb +1 -1
  4. data/lib/webmock/version.rb +1 -1
  5. data/spec/acceptance/curb/curb_spec.rb +36 -36
  6. data/spec/acceptance/em_http_request/em_http_request_spec.rb +24 -24
  7. data/spec/acceptance/excon/excon_spec.rb +11 -11
  8. data/spec/acceptance/httpclient/httpclient_spec.rb +9 -9
  9. data/spec/acceptance/net_http/net_http_shared.rb +23 -23
  10. data/spec/acceptance/net_http/net_http_spec.rb +29 -29
  11. data/spec/acceptance/patron/patron_spec.rb +11 -11
  12. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +29 -29
  13. data/spec/acceptance/shared/callbacks.rb +18 -18
  14. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +3 -3
  15. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +10 -10
  16. data/spec/acceptance/shared/precedence_of_stubs.rb +2 -2
  17. data/spec/acceptance/shared/request_expectations.rb +302 -302
  18. data/spec/acceptance/shared/returning_declared_responses.rb +92 -92
  19. data/spec/acceptance/shared/stubbing_requests.rb +103 -103
  20. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +8 -8
  21. data/spec/quality_spec.rb +3 -3
  22. data/spec/spec_helper.rb +0 -6
  23. data/spec/unit/errors_spec.rb +16 -16
  24. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +1 -1
  25. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +2 -2
  26. data/spec/unit/rack_response_spec.rb +14 -14
  27. data/spec/unit/request_execution_verifier_spec.rb +31 -31
  28. data/spec/unit/request_pattern_spec.rb +202 -197
  29. data/spec/unit/request_registry_spec.rb +10 -9
  30. data/spec/unit/request_signature_spec.rb +21 -20
  31. data/spec/unit/request_stub_spec.rb +54 -53
  32. data/spec/unit/response_spec.rb +44 -44
  33. data/spec/unit/stub_registry_spec.rb +15 -15
  34. data/spec/unit/stub_request_snippet_spec.rb +8 -8
  35. data/spec/unit/util/hash_counter_spec.rb +6 -6
  36. data/spec/unit/util/hash_keys_stringifier_spec.rb +1 -1
  37. data/spec/unit/util/headers_spec.rb +4 -4
  38. data/spec/unit/util/json_spec.rb +1 -1
  39. data/spec/unit/util/uri_spec.rb +30 -30
  40. data/spec/unit/util/version_checker_spec.rb +9 -9
  41. data/spec/unit/webmock_spec.rb +1 -1
  42. data/webmock.gemspec +1 -1
  43. metadata +10 -9
@@ -14,9 +14,9 @@ describe WebMock::RequestRegistry do
14
14
  end
15
15
 
16
16
  it "should clean list of executed requests" do
17
- WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 1
17
+ expect(WebMock::RequestRegistry.instance.times_executed(@request_pattern)).to eq(1)
18
18
  WebMock::RequestRegistry.instance.reset!
19
- WebMock::RequestRegistry.instance.times_executed(@request_pattern).should == 0
19
+ expect(WebMock::RequestRegistry.instance.times_executed(@request_pattern)).to eq(0)
20
20
  end
21
21
 
22
22
  end
@@ -33,15 +33,15 @@ describe WebMock::RequestRegistry do
33
33
  end
34
34
 
35
35
  it "should report 0 if no request matching pattern was requested" do
36
- WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.net")).should == 0
36
+ expect(WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.net"))).to eq(0)
37
37
  end
38
38
 
39
39
  it "should report number of times matching pattern was requested" do
40
- WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.com")).should == 2
40
+ expect(WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, "www.example.com"))).to eq(2)
41
41
  end
42
42
 
43
43
  it "should report number of times all matching pattern were requested" do
44
- WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, /.*example.*/)).should == 3
44
+ expect(WebMock::RequestRegistry.instance.times_executed(WebMock::RequestPattern.new(:get, /.*example.*/))).to eq(3)
45
45
  end
46
46
  end
47
47
 
@@ -49,8 +49,8 @@ describe WebMock::RequestRegistry do
49
49
  it "should return hash of unique request signatures with accumulated number" do
50
50
  WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
51
51
  WebMock::RequestRegistry.instance.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
52
- WebMock::RequestRegistry.instance.requested_signatures.
53
- get(WebMock::RequestSignature.new(:get, "www.example.com")).should == 2
52
+ expect(WebMock::RequestRegistry.instance.requested_signatures.
53
+ get(WebMock::RequestSignature.new(:get, "www.example.com"))).to eq(2)
54
54
  end
55
55
  end
56
56
 
@@ -63,12 +63,13 @@ describe WebMock::RequestRegistry do
63
63
  ].each do |s|
64
64
  WebMock::RequestRegistry.instance.requested_signatures.put(s)
65
65
  end
66
- WebMock::RequestRegistry.instance.to_s.should ==
66
+ expect(WebMock::RequestRegistry.instance.to_s).to eq(
67
67
  "GET http://www.example.com/ was made 2 times\nPUT http://www.example.org/ was made 1 time\n"
68
+ )
68
69
  end
69
70
 
70
71
  it "should output info if no requests were executed" do
71
- WebMock::RequestRegistry.instance.to_s.should == "No requests were made."
72
+ expect(WebMock::RequestRegistry.instance.to_s).to eq("No requests were made.")
72
73
  end
73
74
  end
74
75
 
@@ -5,36 +5,37 @@ describe WebMock::RequestSignature do
5
5
  describe "initialization" do
6
6
 
7
7
  it "should have assigned normalized uri" do
8
- WebMock::Util::URI.should_receive(:normalize_uri).and_return("www.example.kom")
8
+ expect(WebMock::Util::URI).to receive(:normalize_uri).and_return("www.example.kom")
9
9
  signature = WebMock::RequestSignature.new(:get, "www.example.com")
10
- signature.uri.should == "www.example.kom"
10
+ expect(signature.uri).to eq("www.example.kom")
11
11
  end
12
12
 
13
13
  it "should have assigned uri without normalization if uri is URI" do
14
- WebMock::Util::URI.should_not_receive(:normalize_uri)
14
+ expect(WebMock::Util::URI).not_to receive(:normalize_uri)
15
15
  uri = Addressable::URI.parse("www.example.com")
16
16
  signature = WebMock::RequestSignature.new(:get, uri)
17
- signature.uri.should == uri
17
+ expect(signature.uri).to eq(uri)
18
18
  end
19
19
 
20
20
  it "should have assigned normalized headers" do
21
- WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
22
- WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}).headers.should == {'B' => 'b'}
21
+ expect(WebMock::Util::Headers).to receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
22
+ expect(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}).headers).to eq({'B' => 'b'})
23
23
  end
24
24
 
25
25
  it "should have assigned body" do
26
- WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc").body.should == "abc"
26
+ expect(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc").body).to eq("abc")
27
27
  end
28
28
 
29
29
  it "should symbolize the method" do
30
- WebMock::RequestSignature.new('get', "www.example.com", :body => "abc").method.should == :get
30
+ expect(WebMock::RequestSignature.new('get', "www.example.com", :body => "abc").method).to eq(:get)
31
31
  end
32
32
  end
33
33
 
34
34
  it "should report string describing itself" do
35
- WebMock::RequestSignature.new(:get, "www.example.com",
36
- :body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s.should ==
35
+ expect(WebMock::RequestSignature.new(:get, "www.example.com",
36
+ :body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s).to eq(
37
37
  "GET http://www.example.com/ with body 'abc' with headers {'A'=>'a', 'B'=>'b'}"
38
+ )
38
39
  end
39
40
 
40
41
  describe "hash" do
@@ -43,25 +44,25 @@ describe WebMock::RequestSignature do
43
44
  :body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
44
45
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
45
46
  :body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
46
- signature1.hash.should == signature2.hash
47
+ expect(signature1.hash).to eq(signature2.hash)
47
48
  end
48
49
 
49
50
  it "should report different hash for two signatures with different method" do
50
51
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
51
52
  signature2 = WebMock::RequestSignature.new(:put, "www.example.com")
52
- signature1.hash.should_not == signature2.hash
53
+ expect(signature1.hash).not_to eq(signature2.hash)
53
54
  end
54
55
 
55
56
  it "should report different hash for two signatures with different uri" do
56
57
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
57
58
  signature2 = WebMock::RequestSignature.new(:get, "www.example.org")
58
- signature1.hash.should_not == signature2.hash
59
+ expect(signature1.hash).not_to eq(signature2.hash)
59
60
  end
60
61
 
61
62
  it "should report different hash for two signatures with different body" do
62
63
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")
63
64
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "def")
64
- signature1.hash.should_not == signature2.hash
65
+ expect(signature1.hash).not_to eq(signature2.hash)
65
66
  end
66
67
 
67
68
  it "should report different hash for two signatures with different headers" do
@@ -69,7 +70,7 @@ describe WebMock::RequestSignature do
69
70
  :headers => {'A' => 'a'})
70
71
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
71
72
  :headers => {'A' => 'A'})
72
- signature1.hash.should_not == signature2.hash
73
+ expect(signature1.hash).not_to eq(signature2.hash)
73
74
  end
74
75
  end
75
76
 
@@ -82,25 +83,25 @@ describe WebMock::RequestSignature do
82
83
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
83
84
  :body => "abc", :headers => {'A' => 'a', 'B' => 'b'})
84
85
 
85
- signature1.send(method, signature2).should be_true
86
+ expect(signature1.send(method, signature2)).to be_truthy
86
87
  end
87
88
 
88
89
  it "should be false for two signatures with different method" do
89
90
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
90
91
  signature2 = WebMock::RequestSignature.new(:put, "www.example.com")
91
- signature1.send(method, signature2).should be_false
92
+ expect(signature1.send(method, signature2)).to be_falsey
92
93
  end
93
94
 
94
95
  it "should be false for two signatures with different uri" do
95
96
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com")
96
97
  signature2 = WebMock::RequestSignature.new(:get, "www.example.org")
97
- signature1.send(method, signature2).should be_false
98
+ expect(signature1.send(method, signature2)).to be_falsey
98
99
  end
99
100
 
100
101
  it "should be false for two signatures with different body" do
101
102
  signature1 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")
102
103
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com", :body => "def")
103
- signature1.send(method, signature2).should be_false
104
+ expect(signature1.send(method, signature2)).to be_falsey
104
105
  end
105
106
 
106
107
  it "should be false for two signatures with different headers" do
@@ -108,7 +109,7 @@ describe WebMock::RequestSignature do
108
109
  :headers => {'A' => 'a'})
109
110
  signature2 = WebMock::RequestSignature.new(:get, "www.example.com",
110
111
  :headers => {'A' => 'A'})
111
- signature1.send(method, signature2).should be_false
112
+ expect(signature1.send(method, signature2)).to be_falsey
112
113
  end
113
114
  end
114
115
  end
@@ -7,29 +7,30 @@ describe WebMock::RequestStub do
7
7
  end
8
8
 
9
9
  it "should have request pattern with method and uri" do
10
- @request_stub.request_pattern.to_s.should == "GET http://www.example.com/"
10
+ expect(@request_stub.request_pattern.to_s).to eq("GET http://www.example.com/")
11
11
  end
12
12
 
13
13
  it "should have response" do
14
- @request_stub.response.should be_a(WebMock::Response)
14
+ expect(@request_stub.response).to be_a(WebMock::Response)
15
15
  end
16
16
 
17
17
  describe "with" do
18
18
 
19
19
  it "should assign body to request pattern" do
20
20
  @request_stub.with(:body => "abc")
21
- @request_stub.request_pattern.to_s.should == WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").to_s
21
+ expect(@request_stub.request_pattern.to_s).to eq(WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").to_s)
22
22
  end
23
23
 
24
24
  it "should assign normalized headers to request pattern" do
25
25
  @request_stub.with(:headers => {'A' => 'a'})
26
- @request_stub.request_pattern.to_s.should ==
26
+ expect(@request_stub.request_pattern.to_s).to eq(
27
27
  WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
28
+ )
28
29
  end
29
30
 
30
31
  it "should assign given block to request profile" do
31
32
  @request_stub.with { |req| req.body == "abc" }
32
- @request_stub.request_pattern.matches?(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc")).should be_true
33
+ expect(@request_stub.request_pattern.matches?(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))).to be_truthy
33
34
  end
34
35
 
35
36
  end
@@ -38,20 +39,20 @@ describe WebMock::RequestStub do
38
39
 
39
40
  it "should assign response with provided options" do
40
41
  @request_stub.to_return(:body => "abc", :status => 500)
41
- @request_stub.response.body.should == "abc"
42
- @request_stub.response.status.should == [500, ""]
42
+ expect(@request_stub.response.body).to eq("abc")
43
+ expect(@request_stub.response.status).to eq([500, ""])
43
44
  end
44
45
 
45
46
  it "should assign responses with provided options" do
46
47
  @request_stub.to_return([{:body => "abc"}, {:body => "def"}])
47
- [@request_stub.response.body, @request_stub.response.body].should == ["abc", "def"]
48
+ expect([@request_stub.response.body, @request_stub.response.body]).to eq(["abc", "def"])
48
49
  end
49
50
 
50
51
  end
51
52
 
52
53
  describe "then" do
53
54
  it "should return stub without any modifications, acting as syntactic sugar" do
54
- @request_stub.then.should == @request_stub
55
+ expect(@request_stub.then).to eq(@request_stub)
55
56
  end
56
57
  end
57
58
 
@@ -59,27 +60,27 @@ describe WebMock::RequestStub do
59
60
 
60
61
  it "should return responses in a sequence passed as array" do
61
62
  @request_stub.to_return([{:body => "abc"}, {:body => "def"}])
62
- @request_stub.response.body.should == "abc"
63
- @request_stub.response.body.should == "def"
63
+ expect(@request_stub.response.body).to eq("abc")
64
+ expect(@request_stub.response.body).to eq("def")
64
65
  end
65
66
 
66
67
  it "should repeat returning last response" do
67
68
  @request_stub.to_return([{:body => "abc"}, {:body => "def"}])
68
69
  @request_stub.response
69
70
  @request_stub.response
70
- @request_stub.response.body.should == "def"
71
+ expect(@request_stub.response.body).to eq("def")
71
72
  end
72
73
 
73
74
  it "should return responses in a sequence passed as comma separated params" do
74
75
  @request_stub.to_return({:body => "abc"}, {:body => "def"})
75
- @request_stub.response.body.should == "abc"
76
- @request_stub.response.body.should == "def"
76
+ expect(@request_stub.response.body).to eq("abc")
77
+ expect(@request_stub.response.body).to eq("def")
77
78
  end
78
79
 
79
80
  it "should return responses declared in multiple to_return declarations" do
80
81
  @request_stub.to_return({:body => "abc"}).to_return({:body => "def"})
81
- @request_stub.response.body.should == "abc"
82
- @request_stub.response.body.should == "def"
82
+ expect(@request_stub.response.body).to eq("abc")
83
+ expect(@request_stub.response.body).to eq("def")
83
84
  end
84
85
 
85
86
  end
@@ -88,37 +89,37 @@ describe WebMock::RequestStub do
88
89
 
89
90
  it "should assign response with exception to be thrown" do
90
91
  @request_stub.to_raise(ArgumentError)
91
- lambda {
92
+ expect {
92
93
  @request_stub.response.raise_error_if_any
93
- }.should raise_error(ArgumentError, "Exception from WebMock")
94
+ }.to raise_error(ArgumentError, "Exception from WebMock")
94
95
  end
95
96
 
96
97
  it "should assign sequence of responses with response with exception to be thrown" do
97
98
  @request_stub.to_return(:body => "abc").then.to_raise(ArgumentError)
98
- @request_stub.response.body.should == "abc"
99
- lambda {
99
+ expect(@request_stub.response.body).to eq("abc")
100
+ expect {
100
101
  @request_stub.response.raise_error_if_any
101
- }.should raise_error(ArgumentError, "Exception from WebMock")
102
+ }.to raise_error(ArgumentError, "Exception from WebMock")
102
103
  end
103
104
 
104
105
  it "should assign a list responses to be thrown in a sequence" do
105
106
  @request_stub.to_raise(ArgumentError, IndexError)
106
- lambda {
107
+ expect {
107
108
  @request_stub.response.raise_error_if_any
108
- }.should raise_error(ArgumentError, "Exception from WebMock")
109
- lambda {
109
+ }.to raise_error(ArgumentError, "Exception from WebMock")
110
+ expect {
110
111
  @request_stub.response.raise_error_if_any
111
- }.should raise_error(IndexError, "Exception from WebMock")
112
+ }.to raise_error(IndexError, "Exception from WebMock")
112
113
  end
113
114
 
114
115
  it "should raise exceptions declared in multiple to_raise declarations" do
115
116
  @request_stub.to_raise(ArgumentError).then.to_raise(IndexError)
116
- lambda {
117
+ expect {
117
118
  @request_stub.response.raise_error_if_any
118
- }.should raise_error(ArgumentError, "Exception from WebMock")
119
- lambda {
119
+ }.to raise_error(ArgumentError, "Exception from WebMock")
120
+ expect {
120
121
  @request_stub.response.raise_error_if_any
121
- }.should raise_error(IndexError, "Exception from WebMock")
122
+ }.to raise_error(IndexError, "Exception from WebMock")
122
123
  end
123
124
 
124
125
  end
@@ -127,20 +128,20 @@ describe WebMock::RequestStub do
127
128
 
128
129
  it "should assign response with timeout" do
129
130
  @request_stub.to_timeout
130
- @request_stub.response.should_timeout.should be_true
131
+ expect(@request_stub.response.should_timeout).to be_truthy
131
132
  end
132
133
 
133
134
  it "should assign sequence of responses with response with timeout" do
134
135
  @request_stub.to_return(:body => "abc").then.to_timeout
135
- @request_stub.response.body.should == "abc"
136
- @request_stub.response.should_timeout.should be_true
136
+ expect(@request_stub.response.body).to eq("abc")
137
+ expect(@request_stub.response.should_timeout).to be_truthy
137
138
  end
138
139
 
139
140
  it "should allow multiple timeouts to be declared" do
140
141
  @request_stub.to_timeout.then.to_timeout.then.to_return(:body => "abc")
141
- @request_stub.response.should_timeout.should be_true
142
- @request_stub.response.should_timeout.should be_true
143
- @request_stub.response.body.should == "abc"
142
+ expect(@request_stub.response.should_timeout).to be_truthy
143
+ expect(@request_stub.response.should_timeout).to be_truthy
144
+ expect(@request_stub.response.body).to eq("abc")
144
145
  end
145
146
 
146
147
  end
@@ -149,48 +150,48 @@ describe WebMock::RequestStub do
149
150
  describe "times" do
150
151
 
151
152
  it "should give error if declared before any response declaration is declared" do
152
- lambda {
153
+ expect {
153
154
  @request_stub.times(3)
154
- }.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
155
+ }.to raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
155
156
  end
156
157
 
157
158
  it "should repeat returning last declared response declared number of times" do
158
159
  @request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
159
- @request_stub.response.body.should == "abc"
160
- @request_stub.response.body.should == "abc"
161
- @request_stub.response.body.should == "def"
160
+ expect(@request_stub.response.body).to eq("abc")
161
+ expect(@request_stub.response.body).to eq("abc")
162
+ expect(@request_stub.response.body).to eq("def")
162
163
  end
163
164
 
164
165
  it "should repeat raising last declared exception declared number of times" do
165
166
  @request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
166
- @request_stub.response.body.should == "abc"
167
- @request_stub.response.body.should == "abc"
168
- @request_stub.response.body.should == "def"
167
+ expect(@request_stub.response.body).to eq("abc")
168
+ expect(@request_stub.response.body).to eq("abc")
169
+ expect(@request_stub.response.body).to eq("def")
169
170
  end
170
171
 
171
172
  it "should repeat returning last declared sequence of responses declared number of times" do
172
173
  @request_stub.to_return({:body => "abc"}, {:body => "def"}).times(2).then.to_return({:body => "ghj"})
173
- @request_stub.response.body.should == "abc"
174
- @request_stub.response.body.should == "def"
175
- @request_stub.response.body.should == "abc"
176
- @request_stub.response.body.should == "def"
177
- @request_stub.response.body.should == "ghj"
174
+ expect(@request_stub.response.body).to eq("abc")
175
+ expect(@request_stub.response.body).to eq("def")
176
+ expect(@request_stub.response.body).to eq("abc")
177
+ expect(@request_stub.response.body).to eq("def")
178
+ expect(@request_stub.response.body).to eq("ghj")
178
179
  end
179
180
 
180
181
  it "should return self" do
181
- @request_stub.to_return({:body => "abc"}).times(1).should == @request_stub
182
+ expect(@request_stub.to_return({:body => "abc"}).times(1)).to eq(@request_stub)
182
183
  end
183
184
 
184
185
  it "should raise error if argument is not integer" do
185
- lambda {
186
+ expect {
186
187
  @request_stub.to_return({:body => "abc"}).times("not number")
187
- }.should raise_error("times(N) accepts integers >= 1 only")
188
+ }.to raise_error("times(N) accepts integers >= 1 only")
188
189
  end
189
190
 
190
191
  it "should raise error if argument is < 1" do
191
- lambda {
192
+ expect {
192
193
  @request_stub.to_return({:body => "abc"}).times(0)
193
- }.should raise_error("times(N) accepts integers >= 1 only")
194
+ }.to raise_error("times(N) accepts integers >= 1 only")
194
195
  end
195
196
 
196
197
  end
@@ -6,15 +6,15 @@ describe WebMock::ResponseFactory do
6
6
 
7
7
  it "should create response with options passed as arguments" do
8
8
  options = {:body => "abc", :headers => {:a => :b}}
9
- WebMock::Response.should_receive(:new).with(options).and_return(@response = double(WebMock::Response))
10
- WebMock::ResponseFactory.response_for(options).should == @response
9
+ expect(WebMock::Response).to receive(:new).with(options).and_return(@response = double(WebMock::Response))
10
+ expect(WebMock::ResponseFactory.response_for(options)).to eq(@response)
11
11
  end
12
12
 
13
13
 
14
14
  it "should create dynamic response for argument responding to call" do
15
15
  callable = double(:call => {:body => "abc"})
16
- WebMock::DynamicResponse.should_receive(:new).with(callable).and_return(@response = double(WebMock::Response))
17
- WebMock::ResponseFactory.response_for(callable).should == @response
16
+ expect(WebMock::DynamicResponse).to receive(:new).with(callable).and_return(@response = double(WebMock::Response))
17
+ expect(WebMock::ResponseFactory.response_for(callable)).to eq(@response)
18
18
  end
19
19
 
20
20
  end
@@ -31,24 +31,24 @@ describe WebMock::Response do
31
31
  end
32
32
 
33
33
  it "should report normalized headers" do
34
- WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
34
+ expect(WebMock::Util::Headers).to receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
35
35
  @response = WebMock::Response.new(:headers => {'A' => 'a'})
36
- @response.headers.should == {'B' => 'b'}
36
+ expect(@response.headers).to eq({'B' => 'b'})
37
37
  end
38
38
 
39
39
  describe "status" do
40
40
  it "should have 200 code and empty message by default" do
41
- @response.status.should == [200, ""]
41
+ expect(@response.status).to eq([200, ""])
42
42
  end
43
43
 
44
44
  it "should return assigned status" do
45
45
  @response = WebMock::Response.new(:status => 500)
46
- @response.status.should == [500, ""]
46
+ expect(@response.status).to eq([500, ""])
47
47
  end
48
48
 
49
49
  it "should return assigned message" do
50
50
  @response = WebMock::Response.new(:status => [500, "Internal Server Error"])
51
- @response.status.should == [500, "Internal Server Error"]
51
+ expect(@response.status).to eq([500, "Internal Server Error"])
52
52
  end
53
53
  end
54
54
 
@@ -56,23 +56,23 @@ describe WebMock::Response do
56
56
 
57
57
  it "should raise error if any assigned" do
58
58
  @response = WebMock::Response.new(:exception => ArgumentError)
59
- lambda {
59
+ expect {
60
60
  @response.raise_error_if_any
61
- }.should raise_error(ArgumentError, "Exception from WebMock")
61
+ }.to raise_error(ArgumentError, "Exception from WebMock")
62
62
  end
63
63
 
64
64
  it "should raise error if any assigned as instance" do
65
65
  @response = WebMock::Response.new(:exception => ArgumentError.new("hello world"))
66
- lambda {
66
+ expect {
67
67
  @response.raise_error_if_any
68
- }.should raise_error(ArgumentError, "hello world")
68
+ }.to raise_error(ArgumentError, "hello world")
69
69
  end
70
70
 
71
71
  it "should raise error if any assigned as string" do
72
72
  @response = WebMock::Response.new(:exception => "hello world")
73
- lambda {
73
+ expect {
74
74
  @response.raise_error_if_any
75
- }.should raise_error("hello world")
75
+ }.to raise_error("hello world")
76
76
  end
77
77
 
78
78
  it "should not raise error if no error assigned" do
@@ -85,12 +85,12 @@ describe WebMock::Response do
85
85
 
86
86
  it "should know if it should timeout" do
87
87
  @response = WebMock::Response.new(:should_timeout => true)
88
- @response.should_timeout.should be_true
88
+ expect(@response.should_timeout).to be_truthy
89
89
  end
90
90
 
91
91
  it "should not timeout by default" do
92
92
  @response = WebMock::Response.new
93
- @response.should_timeout.should be_false
93
+ expect(@response.should_timeout).to be_falsey
94
94
  end
95
95
 
96
96
  end
@@ -98,40 +98,40 @@ describe WebMock::Response do
98
98
  describe "body" do
99
99
 
100
100
  it "should return empty body by default" do
101
- @response.body.should == ''
101
+ expect(@response.body).to eq('')
102
102
  end
103
103
 
104
104
  it "should report body if assigned" do
105
105
  @response = WebMock::Response.new(:body => "abc")
106
- @response.body.should == "abc"
106
+ expect(@response.body).to eq("abc")
107
107
  end
108
108
 
109
109
  it "should report string even if existing file path was provided" do
110
110
  @response = WebMock::Response.new(:body => __FILE__)
111
- @response.body.should == __FILE__
111
+ expect(@response.body).to eq(__FILE__)
112
112
  end
113
113
 
114
114
  it "should report content of a IO object if provided" do
115
115
  @response = WebMock::Response.new(:body => File.new(__FILE__))
116
- @response.body.should == File.read(__FILE__)
116
+ expect(@response.body).to eq(File.read(__FILE__))
117
117
  end
118
118
 
119
119
  it "should report many times content of a IO object if provided" do
120
120
  @response = WebMock::Response.new(:body => File.new(__FILE__))
121
- @response.body.should == File.read(__FILE__)
122
- @response.body.should == File.read(__FILE__)
121
+ expect(@response.body).to eq(File.read(__FILE__))
122
+ expect(@response.body).to eq(File.read(__FILE__))
123
123
  end
124
124
 
125
125
  it "should work with Pathnames" do
126
126
  @response = WebMock::Response.new(:body => Pathname.new(__FILE__))
127
- @response.body.should == File.read(__FILE__)
127
+ expect(@response.body).to eq(File.read(__FILE__))
128
128
  end
129
129
 
130
130
  # Users of webmock commonly make the mistake of stubbing the response
131
131
  # body to return a hash, to prevent this:
132
132
  #
133
133
  it "should error if not given one of the allowed types" do
134
- lambda { WebMock::Response.new(:body => Hash.new) }.should \
134
+ expect { WebMock::Response.new(:body => Hash.new) }.to \
135
135
  raise_error(WebMock::Response::InvalidBody)
136
136
  end
137
137
 
@@ -147,25 +147,25 @@ describe WebMock::Response do
147
147
 
148
148
 
149
149
  it "should read status" do
150
- @response.status.should == [202, "OK"]
150
+ expect(@response.status).to eq([202, "OK"])
151
151
  end
152
152
 
153
153
  it "should read headers" do
154
- @response.headers.should == {
154
+ expect(@response.headers).to eq({
155
155
  "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
156
156
  "Content-Type"=>"text/html; charset=UTF-8",
157
157
  "Content-Length"=>"419",
158
158
  "Connection"=>"Keep-Alive",
159
159
  "Accept"=>"image/jpeg, image/png"
160
- }
160
+ })
161
161
  end
162
162
 
163
163
  it "should read body" do
164
- @response.body.size.should == 419
164
+ expect(@response.body.size).to eq(419)
165
165
  end
166
166
 
167
167
  it "should close IO" do
168
- @file.should be_closed
168
+ expect(@file).to be_closed
169
169
  end
170
170
 
171
171
  end
@@ -177,27 +177,27 @@ describe WebMock::Response do
177
177
  end
178
178
 
179
179
  it "should read status" do
180
- @response.status.should == [202, "OK"]
180
+ expect(@response.status).to eq([202, "OK"])
181
181
  end
182
182
 
183
183
  it "should read headers" do
184
- @response.headers.should == {
184
+ expect(@response.headers).to eq({
185
185
  "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
186
186
  "Content-Type"=>"text/html; charset=UTF-8",
187
187
  "Content-Length"=>"419",
188
188
  "Connection"=>"Keep-Alive",
189
189
  "Accept"=>"image/jpeg, image/png"
190
- }
190
+ })
191
191
  end
192
192
 
193
193
  it "should read body" do
194
- @response.body.size.should == 419
194
+ expect(@response.body.size).to eq(419)
195
195
  end
196
196
 
197
197
  it "should work with transfer-encoding set to chunked" do
198
198
  @input.gsub!("Content-Length: 419", "Transfer-Encoding: chunked")
199
199
  @response = WebMock::Response.new(@input)
200
- @response.body.size.should == 419
200
+ expect(@response.body.size).to eq(419)
201
201
  end
202
202
 
203
203
  end
@@ -210,17 +210,17 @@ describe WebMock::Response do
210
210
 
211
211
  it "should have evaluated body" do
212
212
  @response = WebMock::Response.new(:body => lambda {|request| request.body})
213
- @response.evaluate(@request_signature).body.should == "abc"
213
+ expect(@response.evaluate(@request_signature).body).to eq("abc")
214
214
  end
215
215
 
216
216
  it "should have evaluated headers" do
217
217
  @response = WebMock::Response.new(:headers => lambda {|request| request.headers})
218
- @response.evaluate(@request_signature).headers.should == {'A' => 'a'}
218
+ expect(@response.evaluate(@request_signature).headers).to eq({'A' => 'a'})
219
219
  end
220
220
 
221
221
  it "should have evaluated status" do
222
222
  @response = WebMock::Response.new(:status => lambda {|request| 302})
223
- @response.evaluate(@request_signature).status.should == [302, ""]
223
+ expect(@response.evaluate(@request_signature).status).to eq([302, ""])
224
224
  end
225
225
 
226
226
  end
@@ -241,16 +241,16 @@ describe WebMock::Response do
241
241
  }
242
242
  })
243
243
  evaluated_response = response.evaluate(request_signature)
244
- evaluated_response.body.should == "abc"
245
- evaluated_response.headers.should == {'A' => 'a'}
246
- evaluated_response.status.should == [302, ""]
244
+ expect(evaluated_response.body).to eq("abc")
245
+ expect(evaluated_response.headers).to eq({'A' => 'a'})
246
+ expect(evaluated_response.status).to eq([302, ""])
247
247
  end
248
248
 
249
249
  it "should be equal to static response after evaluation" do
250
250
  request_signature = WebMock::RequestSignature.new(:post, "www.example.com", :body => "abc")
251
251
  response = WebMock::DynamicResponse.new(lambda {|request| {:body => request.body}})
252
252
  evaluated_response = response.evaluate(request_signature)
253
- evaluated_response.should == WebMock::Response.new(:body => "abc")
253
+ expect(evaluated_response).to eq(WebMock::Response.new(:body => "abc"))
254
254
  end
255
255
 
256
256
  describe "when raw response is evaluated" do
@@ -264,14 +264,14 @@ describe WebMock::Response do
264
264
  describe "as a file" do
265
265
  it "should return response" do
266
266
  response = WebMock::DynamicResponse.new(lambda {|request| @files[request.uri.host.to_s] })
267
- response.evaluate(@request_signature).body.size.should == 419
267
+ expect(response.evaluate(@request_signature).body.size).to eq(419)
268
268
  end
269
269
  end
270
270
 
271
271
  describe "as a string" do
272
272
  it "should return response" do
273
273
  response = WebMock::DynamicResponse.new(lambda {|request| @files[request.uri.host.to_s].read })
274
- response.evaluate(@request_signature).body.size.should == 419
274
+ expect(response.evaluate(@request_signature).body.size).to eq(419)
275
275
  end
276
276
  end
277
277
  end