ruby-resty 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.md +26 -8
  2. data/Rakefile +7 -0
  3. data/lib/resty/cli.rb +21 -13
  4. data/lib/resty/commands/method_command.rb +27 -12
  5. data/lib/resty/{cli_options.rb → options.rb} +20 -12
  6. data/lib/resty/override_pry_help.rb +17 -0
  7. data/lib/resty/pretty_printer.rb +59 -0
  8. data/lib/resty/repl.rb +6 -4
  9. data/lib/resty/request.rb +18 -10
  10. data/lib/resty.rb +6 -3
  11. data/lib/version.rb +1 -1
  12. data/ruby-resty.gemspec +5 -1
  13. data/spec/lib/resty/commands/method_command_spec.rb +22 -14
  14. data/spec/lib/resty/options_spec.rb +111 -0
  15. data/spec/lib/resty/pretty_printer_spec.rb +110 -0
  16. data/spec/lib/resty/request_spec.rb +69 -45
  17. data/spec/requests/commands/method_command_request_spec.rb +150 -0
  18. data/spec/server.rb +34 -0
  19. data/spec/spec_helper.rb +48 -0
  20. data/spec/vcr/method_command/delete_returns_200.yml +79 -0
  21. data/spec/vcr/method_command/delete_sends_headers.yml +46 -0
  22. data/spec/vcr/method_command/get_non_json_response_returns_200.yml +89 -0
  23. data/spec/vcr/method_command/get_non_json_response_returns_response.yml +89 -0
  24. data/spec/vcr/method_command/get_non_json_response_sends_headers.yml +89 -0
  25. data/spec/vcr/method_command/get_returns_200.yml +79 -0
  26. data/spec/vcr/method_command/get_returns_response.yml +79 -0
  27. data/spec/vcr/method_command/get_sends_headers.yml +44 -0
  28. data/spec/vcr/method_command/get_with_per_request_headers_returns_200.yml +46 -0
  29. data/spec/vcr/method_command/get_with_per_request_headers_returns_response.yml +46 -0
  30. data/spec/vcr/method_command/get_with_per_request_headers_sends_headers.yml +46 -0
  31. data/spec/vcr/method_command/get_without_per_request_headers_returns_200.yml +46 -0
  32. data/spec/vcr/method_command/get_without_per_request_headers_returns_response.yml +46 -0
  33. data/spec/vcr/method_command/get_without_per_request_headers_sends_headers.yml +46 -0
  34. data/spec/vcr/method_command/head_returns_200.yml +79 -0
  35. data/spec/vcr/method_command/head_sends_headers.yml +46 -0
  36. data/spec/vcr/method_command/options_returns_200.yml +79 -0
  37. data/spec/vcr/method_command/options_sends_headers.yml +46 -0
  38. data/spec/vcr/method_command/patch_returns_204.yml +87 -0
  39. data/spec/vcr/method_command/patch_sends_headers.yml +50 -0
  40. data/spec/vcr/method_command/post_returns_200.yml +87 -0
  41. data/spec/vcr/method_command/post_returns_created_object.yml +87 -0
  42. data/spec/vcr/method_command/post_sends_headers.yml +50 -0
  43. data/spec/vcr/method_command/put_returns_204.yml +79 -0
  44. data/spec/vcr/method_command/put_sends_headers.yml +42 -0
  45. metadata +135 -16
  46. data/lib/resty/commands/method_output.rb +0 -43
  47. data/spec/lib/resty/cli_options_spec.rb +0 -103
  48. data/spec/lib/resty/commands/method_output_spec.rb +0 -58
@@ -0,0 +1,87 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://nyan:cat@localhost:4567/api/nyan
6
+ body:
7
+ encoding: US-ASCII
8
+ string: nyan=cat
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - "8"
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: "OK "
24
+ headers:
25
+ Content-Type:
26
+ - text/html;charset=utf-8
27
+ Content-Length:
28
+ - "14"
29
+ X-Xss-Protection:
30
+ - 1; mode=block
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ Server:
36
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
37
+ Date:
38
+ - Sun, 07 Jul 2013 19:42:37 GMT
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: "{\"nyan\":\"cat\"}"
44
+ http_version:
45
+ recorded_at: Sun, 07 Jul 2013 19:42:37 GMT
46
+ - request:
47
+ method: post
48
+ uri: http://localhost:4567/api/nyan
49
+ body:
50
+ encoding: US-ASCII
51
+ string: nyan=cat
52
+ headers:
53
+ Accept:
54
+ - "*/*; q=0.5, application/xml"
55
+ Accept-Encoding:
56
+ - gzip, deflate
57
+ Content-Length:
58
+ - "8"
59
+ Content-Type:
60
+ - application/x-www-form-urlencoded
61
+ User-Agent:
62
+ - Ruby
63
+ response:
64
+ status:
65
+ code: 401
66
+ message: "Unauthorized "
67
+ headers:
68
+ Content-Type:
69
+ - text/plain
70
+ Content-Length:
71
+ - "0"
72
+ Www-Authenticate:
73
+ - Basic realm=""
74
+ X-Content-Type-Options:
75
+ - nosniff
76
+ Server:
77
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
78
+ Date:
79
+ - Sun, 07 Jul 2013 19:43:10 GMT
80
+ Connection:
81
+ - Keep-Alive
82
+ body:
83
+ encoding: US-ASCII
84
+ string: ""
85
+ http_version:
86
+ recorded_at: Sun, 07 Jul 2013 19:43:10 GMT
87
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://nyan:cat@localhost:4567/api/nyan
6
+ body:
7
+ encoding: US-ASCII
8
+ string: nyan=cat
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Name:
15
+ - nyaaa
16
+ Color:
17
+ - green
18
+ Content-Length:
19
+ - "8"
20
+ Content-Type:
21
+ - application/x-www-form-urlencoded
22
+ User-Agent:
23
+ - Ruby
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: "OK "
28
+ headers:
29
+ Content-Type:
30
+ - text/html;charset=utf-8
31
+ Content-Length:
32
+ - "14"
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
41
+ Date:
42
+ - Mon, 08 Jul 2013 15:08:52 GMT
43
+ Connection:
44
+ - Keep-Alive
45
+ body:
46
+ encoding: US-ASCII
47
+ string: "{\"nyan\":\"cat\"}"
48
+ http_version:
49
+ recorded_at: Mon, 08 Jul 2013 15:08:52 GMT
50
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,79 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://nyan:cat@localhost:4567/api/nyan
6
+ body:
7
+ encoding: US-ASCII
8
+ string: nyan=cat
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - "8"
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 204
23
+ message: "No Content "
24
+ headers:
25
+ X-Content-Type-Options:
26
+ - nosniff
27
+ Server:
28
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
29
+ Date:
30
+ - Sun, 07 Jul 2013 19:42:37 GMT
31
+ Connection:
32
+ - close
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ""
36
+ http_version:
37
+ recorded_at: Sun, 07 Jul 2013 19:42:37 GMT
38
+ - request:
39
+ method: put
40
+ uri: http://localhost:4567/api/nyan
41
+ body:
42
+ encoding: US-ASCII
43
+ string: nyan=cat
44
+ headers:
45
+ Accept:
46
+ - "*/*; q=0.5, application/xml"
47
+ Accept-Encoding:
48
+ - gzip, deflate
49
+ Content-Length:
50
+ - "8"
51
+ Content-Type:
52
+ - application/x-www-form-urlencoded
53
+ User-Agent:
54
+ - Ruby
55
+ response:
56
+ status:
57
+ code: 401
58
+ message: "Unauthorized "
59
+ headers:
60
+ Content-Type:
61
+ - text/plain
62
+ Content-Length:
63
+ - "0"
64
+ Www-Authenticate:
65
+ - Basic realm=""
66
+ X-Content-Type-Options:
67
+ - nosniff
68
+ Server:
69
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
70
+ Date:
71
+ - Sun, 07 Jul 2013 19:43:10 GMT
72
+ Connection:
73
+ - Keep-Alive
74
+ body:
75
+ encoding: US-ASCII
76
+ string: ""
77
+ http_version:
78
+ recorded_at: Sun, 07 Jul 2013 19:43:10 GMT
79
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://nyan:cat@localhost:4567/api/nyan
6
+ body:
7
+ encoding: US-ASCII
8
+ string: nyan=cat
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Name:
15
+ - nyaaa
16
+ Color:
17
+ - green
18
+ Content-Length:
19
+ - "8"
20
+ Content-Type:
21
+ - application/x-www-form-urlencoded
22
+ User-Agent:
23
+ - Ruby
24
+ response:
25
+ status:
26
+ code: 204
27
+ message: "No Content "
28
+ headers:
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ Server:
32
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
33
+ Date:
34
+ - Mon, 08 Jul 2013 15:08:57 GMT
35
+ Connection:
36
+ - close
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ""
40
+ http_version:
41
+ recorded_at: Mon, 08 Jul 2013 15:08:57 GMT
42
+ recorded_with: VCR 2.5.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-resty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_support
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: pry
31
+ name: hashie
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,23 +44,23 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rest-client
47
+ name: multi_json
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - '='
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 1.6.7
53
+ version: '0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - '='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.7
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: trollop
63
+ name: pry
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -76,7 +76,23 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: multi_json
79
+ name: rest-client
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.6.7
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.6.7
94
+ - !ruby/object:Gem::Dependency
95
+ name: trollop
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
@@ -203,6 +219,54 @@ dependencies:
203
219
  - - ! '>='
204
220
  - !ruby/object:Gem::Version
205
221
  version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: sinatra
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: vcr
240
+ requirement: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ - !ruby/object:Gem::Dependency
255
+ name: webmock
256
+ requirement: !ruby/object:Gem::Requirement
257
+ none: false
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ type: :development
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
206
270
  description: ''
207
271
  email:
208
272
  - austen.dev@gmail.com
@@ -222,18 +286,46 @@ files:
222
286
  - bin/ruby-resty
223
287
  - lib/resty.rb
224
288
  - lib/resty/cli.rb
225
- - lib/resty/cli_options.rb
226
289
  - lib/resty/commands/method_command.rb
227
- - lib/resty/commands/method_output.rb
290
+ - lib/resty/options.rb
291
+ - lib/resty/override_pry_help.rb
292
+ - lib/resty/pretty_printer.rb
228
293
  - lib/resty/repl.rb
229
294
  - lib/resty/request.rb
230
295
  - lib/version.rb
231
296
  - ruby-resty.gemspec
232
- - spec/lib/resty/cli_options_spec.rb
233
297
  - spec/lib/resty/commands/method_command_spec.rb
234
- - spec/lib/resty/commands/method_output_spec.rb
298
+ - spec/lib/resty/options_spec.rb
299
+ - spec/lib/resty/pretty_printer_spec.rb
235
300
  - spec/lib/resty/request_spec.rb
301
+ - spec/requests/commands/method_command_request_spec.rb
302
+ - spec/server.rb
236
303
  - spec/spec_helper.rb
304
+ - spec/vcr/method_command/delete_returns_200.yml
305
+ - spec/vcr/method_command/delete_sends_headers.yml
306
+ - spec/vcr/method_command/get_non_json_response_returns_200.yml
307
+ - spec/vcr/method_command/get_non_json_response_returns_response.yml
308
+ - spec/vcr/method_command/get_non_json_response_sends_headers.yml
309
+ - spec/vcr/method_command/get_returns_200.yml
310
+ - spec/vcr/method_command/get_returns_response.yml
311
+ - spec/vcr/method_command/get_sends_headers.yml
312
+ - spec/vcr/method_command/get_with_per_request_headers_returns_200.yml
313
+ - spec/vcr/method_command/get_with_per_request_headers_returns_response.yml
314
+ - spec/vcr/method_command/get_with_per_request_headers_sends_headers.yml
315
+ - spec/vcr/method_command/get_without_per_request_headers_returns_200.yml
316
+ - spec/vcr/method_command/get_without_per_request_headers_returns_response.yml
317
+ - spec/vcr/method_command/get_without_per_request_headers_sends_headers.yml
318
+ - spec/vcr/method_command/head_returns_200.yml
319
+ - spec/vcr/method_command/head_sends_headers.yml
320
+ - spec/vcr/method_command/options_returns_200.yml
321
+ - spec/vcr/method_command/options_sends_headers.yml
322
+ - spec/vcr/method_command/patch_returns_204.yml
323
+ - spec/vcr/method_command/patch_sends_headers.yml
324
+ - spec/vcr/method_command/post_returns_200.yml
325
+ - spec/vcr/method_command/post_returns_created_object.yml
326
+ - spec/vcr/method_command/post_sends_headers.yml
327
+ - spec/vcr/method_command/put_returns_204.yml
328
+ - spec/vcr/method_command/put_sends_headers.yml
237
329
  - templates/ruby_resty.yml
238
330
  homepage: ''
239
331
  licenses: []
@@ -260,8 +352,35 @@ signing_key:
260
352
  specification_version: 3
261
353
  summary: ''
262
354
  test_files:
263
- - spec/lib/resty/cli_options_spec.rb
264
355
  - spec/lib/resty/commands/method_command_spec.rb
265
- - spec/lib/resty/commands/method_output_spec.rb
356
+ - spec/lib/resty/options_spec.rb
357
+ - spec/lib/resty/pretty_printer_spec.rb
266
358
  - spec/lib/resty/request_spec.rb
359
+ - spec/requests/commands/method_command_request_spec.rb
360
+ - spec/server.rb
267
361
  - spec/spec_helper.rb
362
+ - spec/vcr/method_command/delete_returns_200.yml
363
+ - spec/vcr/method_command/delete_sends_headers.yml
364
+ - spec/vcr/method_command/get_non_json_response_returns_200.yml
365
+ - spec/vcr/method_command/get_non_json_response_returns_response.yml
366
+ - spec/vcr/method_command/get_non_json_response_sends_headers.yml
367
+ - spec/vcr/method_command/get_returns_200.yml
368
+ - spec/vcr/method_command/get_returns_response.yml
369
+ - spec/vcr/method_command/get_sends_headers.yml
370
+ - spec/vcr/method_command/get_with_per_request_headers_returns_200.yml
371
+ - spec/vcr/method_command/get_with_per_request_headers_returns_response.yml
372
+ - spec/vcr/method_command/get_with_per_request_headers_sends_headers.yml
373
+ - spec/vcr/method_command/get_without_per_request_headers_returns_200.yml
374
+ - spec/vcr/method_command/get_without_per_request_headers_returns_response.yml
375
+ - spec/vcr/method_command/get_without_per_request_headers_sends_headers.yml
376
+ - spec/vcr/method_command/head_returns_200.yml
377
+ - spec/vcr/method_command/head_sends_headers.yml
378
+ - spec/vcr/method_command/options_returns_200.yml
379
+ - spec/vcr/method_command/options_sends_headers.yml
380
+ - spec/vcr/method_command/patch_returns_204.yml
381
+ - spec/vcr/method_command/patch_sends_headers.yml
382
+ - spec/vcr/method_command/post_returns_200.yml
383
+ - spec/vcr/method_command/post_returns_created_object.yml
384
+ - spec/vcr/method_command/post_sends_headers.yml
385
+ - spec/vcr/method_command/put_returns_204.yml
386
+ - spec/vcr/method_command/put_sends_headers.yml
@@ -1,43 +0,0 @@
1
- module Resty
2
- module Commands
3
- class MethodOutput
4
- attr_accessor :verbose, :response, :request
5
-
6
- def initialize(verbose, response, request)
7
- @verbose = verbose
8
- @response = response
9
- @request = request
10
- end
11
-
12
- def generate
13
- output = ""
14
- if verbose
15
- output += build_line("#{request.method.upcase} #{request.url}")
16
- request.processed_headers.each { |key, value| output += build_line("#{key}: #{value}") }
17
- output += "\n"
18
-
19
- output += build_line("Response Code: #{response.code}")
20
- response.headers.each { |key, value| output += build_line("#{key}: #{value}") }
21
- else
22
- output += build_line("Response Code: #{response.code}")
23
- end
24
-
25
- output += pretty_json(response)
26
- end
27
-
28
- private
29
-
30
- def build_line(line)
31
- "> #{line}\n"
32
- end
33
-
34
- def pretty_json(json)
35
- return json if json == ""
36
- parsed_json = JSON.parse(json)
37
- MultiJson.dump(parsed_json, { pretty: true }) || ""
38
- rescue => e
39
- ""
40
- end
41
- end
42
- end
43
- end
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Resty::CliOptions do
4
-
5
- context "#host" do
6
- let(:options) { Resty::CliOptions.new(host: "foo.com") }
7
-
8
- it "returns host" do
9
- expect(options.host).to eq("foo.com")
10
- end
11
- end
12
-
13
- context "#headers" do
14
- context "with command-line headers" do
15
- let(:options) { Resty::CliOptions.new(host: "foo.com", headers: ["key=star", "type=ninja"],
16
- alias: "nyan") }
17
-
18
- it "returns headers" do
19
- expect(options.headers).to eq(key: "star", type: "ninja")
20
- end
21
-
22
- it "doesn't read config file" do
23
- options.should have_received(:load_config_file).never
24
- end
25
- end
26
-
27
- context "empty headers" do
28
- let(:options) { Resty::CliOptions.new({}) }
29
-
30
- it "returns empty hash" do
31
- expect(options.headers).to eq({})
32
- end
33
- end
34
- end
35
-
36
- context "alias" do
37
- context "alias exists" do
38
- context "headers exist" do
39
- before(:each) do
40
- YAML.stubs(:load_file).returns({"nyan" => { "host" => "nyan.cat",
41
- "headers" => { "header" => "value" } } })
42
- File.stubs(:exist?).returns(true)
43
- @options = Resty::CliOptions.new(alias: "nyan")
44
- end
45
-
46
- it "returns host" do
47
- expect(@options.host).to eq("nyan.cat")
48
- end
49
-
50
- it "returns headers" do
51
- expect(@options.headers).to eq("header" => "value")
52
- end
53
-
54
- it "loads YAML file" do
55
- YAML.should have_received(:load_file).with("#{Dir.home}/.ruby_resty.yml")
56
- end
57
- end
58
- end
59
-
60
- context "headers don't exist" do
61
- before(:each) do
62
- YAML.stubs(:load_file).returns({"nyan" => { "host" => "nyan.cat" } } )
63
- File.stubs(:exist?).returns(true)
64
- @options = Resty::CliOptions.new(alias: "nyan")
65
- end
66
-
67
- it "returns host" do
68
- expect(@options.host).to eq("nyan.cat")
69
- end
70
-
71
- it "returns headers" do
72
- expect(@options.headers).to eq({})
73
- end
74
-
75
- it "loads YAML file" do
76
- YAML.should have_received(:load_file).with("#{Dir.home}/.ruby_resty.yml")
77
- end
78
- end
79
-
80
- context "config file doesn't exist" do
81
- it "raises ConfigFileError" do
82
- File.stubs(:exist?).returns(false)
83
- expect { Resty::CliOptions.new(alias: "nyan") }.to raise_error(Resty::ConfigFileError)
84
- end
85
- end
86
-
87
- context "alias doesn't exist" do
88
- it "raises ConfigFileError" do
89
- YAML.stubs(:load_file).returns({"ice_cream" => {} } )
90
- File.stubs(:exist?).returns(true)
91
- expect { Resty::CliOptions.new(alias: "nyan") }.to raise_error(Resty::ConfigFileError)
92
- end
93
- end
94
-
95
- context "host doesn't exist" do
96
- it "raises error" do
97
- YAML.stubs(:load_file).returns({"nyan" => {}})
98
- File.stubs(:exist?).returns(true)
99
- expect { Resty::CliOptions.new(alias: "nyan") }.to raise_error(Resty::ConfigFileError)
100
- end
101
- end
102
- end
103
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'json'
3
-
4
- describe Resty::Commands::MethodOutput do
5
- let(:request) { stub }
6
- let(:response) { JSON.dump({foo: "bar"}) }
7
-
8
- context "#print" do
9
- before(:each) do
10
- response.stubs(:code).returns(200)
11
- end
12
-
13
- context "non-verbose" do
14
- let(:method_output) { Resty::Commands::MethodOutput.new(false, response, request) }
15
-
16
- it "returns output" do
17
- output = <<-eos.unindent
18
- > Response Code: 200
19
- {
20
- "foo": "bar"
21
- }
22
- eos
23
-
24
- # multi-line text adds an extra \n, so let's ignore it
25
- method_output.generate.should eq(output[0..-2])
26
- end
27
- end
28
-
29
- context "verbose" do
30
- let(:method_output) { Resty::Commands::MethodOutput.new(true, response, request) }
31
-
32
- before(:each) do
33
- request.stubs(:method).returns("get")
34
- request.stubs(:url).returns("foo.com")
35
- request.stubs(:processed_headers).returns(header: "value", header2: "value2")
36
- response.stubs(:headers).returns(response_header: "value", response_header2: "value2")
37
- end
38
-
39
- it "returns verbose output" do
40
- output = <<-eos.unindent
41
- > GET foo.com
42
- > header: value
43
- > header2: value2
44
-
45
- > Response Code: 200
46
- > response_header: value
47
- > response_header2: value2
48
- {
49
- "foo": "bar"
50
- }
51
- eos
52
-
53
- # multi-line text adds an extra \n, so let's ignore it
54
- method_output.generate.should eq(output[0..-2])
55
- end
56
- end
57
- end
58
- end