Skip to content

Commit fc38476

Browse files
author
Nuo Yan
committed
fix knife spec tests
1 parent 2becd16 commit fc38476

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎chef/spec/unit/knife_spec.rb‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class SuperAwesomeCommand < Chef::Knife
184184
it "formats 401s nicely" do
185185
response = Net::HTTPUnauthorized.new("1.1", "401", "Unauthorized")
186186
response.instance_variable_set(:@read, true) # I hate you, net/http.
187-
response.body = Chef::JSONCompat.to_json(:error => "y u no syncronize your clock?")
187+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no syncronize your clock?"))
188188
@knife.stub!(:run).and_raise(Net::HTTPServerException.new("401 Unauthorized", response))
189189
@knife.run_with_pretty_exceptions
190190
@stdout.string.should match(/ERROR: Failed to authenticate to/)
@@ -194,7 +194,7 @@ class SuperAwesomeCommand < Chef::Knife
194194
it "formats 403s nicely" do
195195
response = Net::HTTPForbidden.new("1.1", "403", "Forbidden")
196196
response.instance_variable_set(:@read, true) # I hate you, net/http.
197-
response.body = Chef::JSONCompat.to_json(:error => "y u no administrator")
197+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no administrator"))
198198
@knife.stub!(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response))
199199
@knife.stub!(:username).and_return("sadpanda")
200200
@knife.run_with_pretty_exceptions
@@ -205,7 +205,7 @@ class SuperAwesomeCommand < Chef::Knife
205205
it "formats 400s nicely" do
206206
response = Net::HTTPBadRequest.new("1.1", "400", "Bad Request")
207207
response.instance_variable_set(:@read, true) # I hate you, net/http.
208-
response.body = Chef::JSONCompat.to_json(:error => "y u search wrong")
208+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u search wrong"))
209209
@knife.stub!(:run).and_raise(Net::HTTPServerException.new("400 Bad Request", response))
210210
@knife.run_with_pretty_exceptions
211211
@stdout.string.should match(%r[ERROR: The data in your request was invalid])
@@ -215,7 +215,7 @@ class SuperAwesomeCommand < Chef::Knife
215215
it "formats 404s nicely" do
216216
response = Net::HTTPNotFound.new("1.1", "404", "Not Found")
217217
response.instance_variable_set(:@read, true) # I hate you, net/http.
218-
response.body = Chef::JSONCompat.to_json(:error => "nothing to see here")
218+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "nothing to see here"))
219219
@knife.stub!(:run).and_raise(Net::HTTPServerException.new("404 Not Found", response))
220220
@knife.run_with_pretty_exceptions
221221
@stdout.string.should match(%r[ERROR: The object you are looking for could not be found])
@@ -225,7 +225,7 @@ class SuperAwesomeCommand < Chef::Knife
225225
it "formats 500s nicely" do
226226
response = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
227227
response.instance_variable_set(:@read, true) # I hate you, net/http.
228-
response.body = Chef::JSONCompat.to_json(:error => "sad trombone")
228+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone"))
229229
@knife.stub!(:run).and_raise(Net::HTTPFatalError.new("500 Internal Server Error", response))
230230
@knife.run_with_pretty_exceptions
231231
@stdout.string.should match(%r[ERROR: internal server error])
@@ -235,7 +235,7 @@ class SuperAwesomeCommand < Chef::Knife
235235
it "formats 502s nicely" do
236236
response = Net::HTTPBadGateway.new("1.1", "502", "Bad Gateway")
237237
response.instance_variable_set(:@read, true) # I hate you, net/http.
238-
response.body = Chef::JSONCompat.to_json(:error => "sadder trombone")
238+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "sadder trombone"))
239239
@knife.stub!(:run).and_raise(Net::HTTPFatalError.new("502 Bad Gateway", response))
240240
@knife.run_with_pretty_exceptions
241241
@stdout.string.should match(%r[ERROR: bad gateway])
@@ -245,7 +245,7 @@ class SuperAwesomeCommand < Chef::Knife
245245
it "formats 503s nicely" do
246246
response = Net::HTTPServiceUnavailable.new("1.1", "503", "Service Unavailable")
247247
response.instance_variable_set(:@read, true) # I hate you, net/http.
248-
response.body = Chef::JSONCompat.to_json(:error => "saddest trombone")
248+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "saddest trombone"))
249249
@knife.stub!(:run).and_raise(Net::HTTPFatalError.new("503 Service Unavailable", response))
250250
@knife.run_with_pretty_exceptions
251251
@stdout.string.should match(%r[ERROR: Service temporarily unavailable])
@@ -255,7 +255,7 @@ class SuperAwesomeCommand < Chef::Knife
255255
it "formats other HTTP errors nicely" do
256256
response = Net::HTTPPaymentRequired.new("1.1", "402", "Payment Required")
257257
response.instance_variable_set(:@read, true) # I hate you, net/http.
258-
response.body = Chef::JSONCompat.to_json(:error => "nobugfixtillyoubuy")
258+
response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "nobugfixtillyoubuy"))
259259
@knife.stub!(:run).and_raise(Net::HTTPServerException.new("402 Payment Required", response))
260260
@knife.run_with_pretty_exceptions
261261
@stdout.string.should match(%r[ERROR: Payment Required])

0 commit comments

Comments
 (0)