htty 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -9
  3. data/.rspec +2 -1
  4. data/.travis.yml +11 -8
  5. data/.yardopts +1 -1
  6. data/Gemfile +22 -10
  7. data/Guardfile +31 -13
  8. data/History.markdown +6 -0
  9. data/README.markdown +29 -13
  10. data/Rakefile +2 -64
  11. data/bin/console +10 -0
  12. data/bin/setup +8 -0
  13. data/exe/htty +5 -0
  14. data/htty.gemspec +27 -29
  15. data/lib/htty.rb +29 -4
  16. data/lib/htty/cli.rb +9 -16
  17. data/lib/htty/cli/body_open_command.rb +2 -7
  18. data/lib/htty/cli/command.rb +10 -18
  19. data/lib/htty/cli/commands.rb +76 -11
  20. data/lib/htty/cli/commands/address.rb +1 -14
  21. data/lib/htty/cli/commands/body_clear.rb +1 -8
  22. data/lib/htty/cli/commands/body_edit.rb +1 -11
  23. data/lib/htty/cli/commands/body_request.rb +1 -12
  24. data/lib/htty/cli/commands/body_request_open.rb +1 -10
  25. data/lib/htty/cli/commands/body_response.rb +1 -12
  26. data/lib/htty/cli/commands/body_response_open.rb +1 -11
  27. data/lib/htty/cli/commands/body_set.rb +1 -10
  28. data/lib/htty/cli/commands/body_unset.rb +1 -9
  29. data/lib/htty/cli/commands/cd.rb +1 -8
  30. data/lib/htty/cli/commands/cookie_add.rb +1 -8
  31. data/lib/htty/cli/commands/cookie_remove.rb +1 -8
  32. data/lib/htty/cli/commands/cookies.rb +1 -15
  33. data/lib/htty/cli/commands/cookies_add.rb +1 -11
  34. data/lib/htty/cli/commands/cookies_clear.rb +1 -8
  35. data/lib/htty/cli/commands/cookies_remove.rb +1 -11
  36. data/lib/htty/cli/commands/cookies_remove_all.rb +1 -11
  37. data/lib/htty/cli/commands/cookies_use.rb +1 -14
  38. data/lib/htty/cli/commands/delete.rb +1 -8
  39. data/lib/htty/cli/commands/exit.rb +1 -8
  40. data/lib/htty/cli/commands/follow.rb +1 -10
  41. data/lib/htty/cli/commands/form.rb +1 -7
  42. data/lib/htty/cli/commands/form_add.rb +1 -7
  43. data/lib/htty/cli/commands/form_clear.rb +1 -8
  44. data/lib/htty/cli/commands/form_remove.rb +1 -7
  45. data/lib/htty/cli/commands/form_remove_all.rb +1 -7
  46. data/lib/htty/cli/commands/fragment_clear.rb +1 -8
  47. data/lib/htty/cli/commands/fragment_set.rb +1 -10
  48. data/lib/htty/cli/commands/fragment_unset.rb +1 -9
  49. data/lib/htty/cli/commands/get.rb +1 -8
  50. data/lib/htty/cli/commands/header_set.rb +1 -8
  51. data/lib/htty/cli/commands/header_unset.rb +1 -8
  52. data/lib/htty/cli/commands/headers_clear.rb +1 -8
  53. data/lib/htty/cli/commands/headers_request.rb +1 -15
  54. data/lib/htty/cli/commands/headers_response.rb +1 -15
  55. data/lib/htty/cli/commands/headers_set.rb +1 -10
  56. data/lib/htty/cli/commands/headers_unset.rb +1 -10
  57. data/lib/htty/cli/commands/headers_unset_all.rb +1 -10
  58. data/lib/htty/cli/commands/help.rb +4 -12
  59. data/lib/htty/cli/commands/history.rb +1 -10
  60. data/lib/htty/cli/commands/history_verbose.rb +1 -12
  61. data/lib/htty/cli/commands/host_set.rb +1 -8
  62. data/lib/htty/cli/commands/http_delete.rb +1 -12
  63. data/lib/htty/cli/commands/http_get.rb +1 -13
  64. data/lib/htty/cli/commands/http_head.rb +1 -9
  65. data/lib/htty/cli/commands/http_options.rb +1 -9
  66. data/lib/htty/cli/commands/http_patch.rb +1 -13
  67. data/lib/htty/cli/commands/http_post.rb +1 -13
  68. data/lib/htty/cli/commands/http_put.rb +1 -12
  69. data/lib/htty/cli/commands/http_trace.rb +1 -9
  70. data/lib/htty/cli/commands/patch.rb +1 -8
  71. data/lib/htty/cli/commands/path_set.rb +11 -11
  72. data/lib/htty/cli/commands/port_set.rb +1 -9
  73. data/lib/htty/cli/commands/post.rb +1 -8
  74. data/lib/htty/cli/commands/put.rb +1 -8
  75. data/lib/htty/cli/commands/query_add.rb +1 -13
  76. data/lib/htty/cli/commands/query_clear.rb +1 -8
  77. data/lib/htty/cli/commands/query_remove.rb +1 -13
  78. data/lib/htty/cli/commands/query_set.rb +1 -13
  79. data/lib/htty/cli/commands/query_unset.rb +1 -13
  80. data/lib/htty/cli/commands/query_unset_all.rb +1 -10
  81. data/lib/htty/cli/commands/quit.rb +1 -7
  82. data/lib/htty/cli/commands/reuse.rb +5 -12
  83. data/lib/htty/cli/commands/scheme_set.rb +1 -9
  84. data/lib/htty/cli/commands/ssl_verification.rb +1 -11
  85. data/lib/htty/cli/commands/ssl_verification_off.rb +1 -10
  86. data/lib/htty/cli/commands/ssl_verification_on.rb +1 -10
  87. data/lib/htty/cli/commands/status.rb +1 -11
  88. data/lib/htty/cli/commands/undo.rb +1 -7
  89. data/lib/htty/cli/commands/userinfo_clear.rb +1 -8
  90. data/lib/htty/cli/commands/userinfo_set.rb +1 -11
  91. data/lib/htty/cli/commands/userinfo_unset.rb +1 -9
  92. data/lib/htty/cli/display.rb +4 -6
  93. data/lib/htty/cli/http_method_command.rb +1 -10
  94. data/lib/htty/cli/input_device.rb +1 -0
  95. data/lib/htty/cli/url_escaping.rb +1 -6
  96. data/lib/htty/cookies_util.rb +3 -3
  97. data/lib/htty/headers.rb +3 -4
  98. data/lib/htty/http_patch.rb +20 -23
  99. data/lib/htty/no_header_error.rb +1 -1
  100. data/lib/htty/no_location_header_error.rb +1 -3
  101. data/lib/htty/no_response_error.rb +1 -1
  102. data/lib/htty/no_set_cookie_header_error.rb +1 -3
  103. data/lib/htty/payload.rb +1 -5
  104. data/lib/htty/platform.rb +1 -1
  105. data/lib/htty/preferences.rb +1 -1
  106. data/lib/htty/request.rb +3 -13
  107. data/lib/htty/requests_util.rb +1 -5
  108. data/lib/htty/response.rb +1 -4
  109. data/lib/htty/session.rb +1 -3
  110. data/lib/htty/tempfile_preserving_extname.rb +1 -2
  111. data/lib/htty/uri.rb +1 -2
  112. data/lib/htty/version.rb +1 -1
  113. data/lib/tasks.rb +3 -0
  114. data/lib/tasks/build_doc.rake +8 -0
  115. data/lib/tasks/lib_each.rake +25 -0
  116. data/lib/tasks/spec.rake +68 -0
  117. data/lib/tasks/spec_each.rake +19 -0
  118. metadata +48 -209
  119. data/bin/htty +0 -5
  120. data/spec/integration/htty/cli/commands/query_add_spec.rb +0 -57
  121. data/spec/integration/htty/cli/commands/query_remove_spec.rb +0 -55
  122. data/spec/integration/htty/cli/commands/query_set_spec.rb +0 -78
  123. data/spec/integration/htty/cli/commands/query_unset_spec.rb +0 -43
  124. data/spec/spec_helper.rb +0 -76
  125. data/spec/unit/htty/cli/commands/address_spec.rb +0 -103
  126. data/spec/unit/htty/cli/commands/body_clear_spec.rb +0 -64
  127. data/spec/unit/htty/cli/commands/body_edit_spec.rb +0 -18
  128. data/spec/unit/htty/cli/commands/body_request_spec.rb +0 -67
  129. data/spec/unit/htty/cli/commands/body_response_spec.rb +0 -72
  130. data/spec/unit/htty/cli/commands/body_set_spec.rb +0 -71
  131. data/spec/unit/htty/cli/commands/body_unset_spec.rb +0 -69
  132. data/spec/unit/htty/cli/commands/cd_spec.rb +0 -57
  133. data/spec/unit/htty/cli/commands/cookie_add_spec.rb +0 -64
  134. data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +0 -64
  135. data/spec/unit/htty/cli/commands/cookies_add_spec.rb +0 -78
  136. data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +0 -64
  137. data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +0 -73
  138. data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +0 -69
  139. data/spec/unit/htty/cli/commands/cookies_spec.rb +0 -76
  140. data/spec/unit/htty/cli/commands/cookies_use_spec.rb +0 -75
  141. data/spec/unit/htty/cli/commands/delete_spec.rb +0 -64
  142. data/spec/unit/htty/cli/commands/exit_spec.rb +0 -64
  143. data/spec/unit/htty/cli/commands/follow_spec.rb +0 -70
  144. data/spec/unit/htty/cli/commands/form_add_spec.rb +0 -64
  145. data/spec/unit/htty/cli/commands/form_clear_spec.rb +0 -64
  146. data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +0 -66
  147. data/spec/unit/htty/cli/commands/form_remove_spec.rb +0 -57
  148. data/spec/unit/htty/cli/commands/form_spec.rb +0 -57
  149. data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +0 -64
  150. data/spec/unit/htty/cli/commands/fragment_set_spec.rb +0 -73
  151. data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +0 -72
  152. data/spec/unit/htty/cli/commands/get_spec.rb +0 -64
  153. data/spec/unit/htty/cli/commands/header_set_spec.rb +0 -64
  154. data/spec/unit/htty/cli/commands/header_unset_spec.rb +0 -64
  155. data/spec/unit/htty/cli/commands/headers_clear_spec.rb +0 -64
  156. data/spec/unit/htty/cli/commands/headers_request_spec.rb +0 -81
  157. data/spec/unit/htty/cli/commands/headers_response_spec.rb +0 -77
  158. data/spec/unit/htty/cli/commands/headers_set_spec.rb +0 -74
  159. data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +0 -71
  160. data/spec/unit/htty/cli/commands/headers_unset_spec.rb +0 -63
  161. data/spec/unit/htty/cli/commands/help_spec.rb +0 -67
  162. data/spec/unit/htty/cli/commands/history_spec.rb +0 -65
  163. data/spec/unit/htty/cli/commands/history_verbose_spec.rb +0 -72
  164. data/spec/unit/htty/cli/commands/host_set_spec.rb +0 -71
  165. data/spec/unit/htty/cli/commands/http_delete_spec.rb +0 -75
  166. data/spec/unit/htty/cli/commands/http_get_spec.rb +0 -77
  167. data/spec/unit/htty/cli/commands/http_head_spec.rb +0 -69
  168. data/spec/unit/htty/cli/commands/http_options_spec.rb +0 -69
  169. data/spec/unit/htty/cli/commands/http_patch_spec.rb +0 -73
  170. data/spec/unit/htty/cli/commands/http_post_spec.rb +0 -73
  171. data/spec/unit/htty/cli/commands/http_put_spec.rb +0 -71
  172. data/spec/unit/htty/cli/commands/http_trace_spec.rb +0 -69
  173. data/spec/unit/htty/cli/commands/patch_spec.rb +0 -64
  174. data/spec/unit/htty/cli/commands/path_set_spec.rb +0 -72
  175. data/spec/unit/htty/cli/commands/port_set_spec.rb +0 -73
  176. data/spec/unit/htty/cli/commands/post_spec.rb +0 -64
  177. data/spec/unit/htty/cli/commands/put_spec.rb +0 -64
  178. data/spec/unit/htty/cli/commands/query_add_spec.rb +0 -82
  179. data/spec/unit/htty/cli/commands/query_clear_spec.rb +0 -64
  180. data/spec/unit/htty/cli/commands/query_remove_spec.rb +0 -82
  181. data/spec/unit/htty/cli/commands/query_set_spec.rb +0 -82
  182. data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +0 -74
  183. data/spec/unit/htty/cli/commands/query_unset_spec.rb +0 -75
  184. data/spec/unit/htty/cli/commands/quit_spec.rb +0 -64
  185. data/spec/unit/htty/cli/commands/reuse_spec.rb +0 -72
  186. data/spec/unit/htty/cli/commands/scheme_set_spec.rb +0 -74
  187. data/spec/unit/htty/cli/commands/shared_examples_for_commands.rb +0 -55
  188. data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +0 -67
  189. data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +0 -60
  190. data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +0 -65
  191. data/spec/unit/htty/cli/commands/status_spec.rb +0 -73
  192. data/spec/unit/htty/cli/commands/undo_spec.rb +0 -57
  193. data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +0 -64
  194. data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +0 -97
  195. data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +0 -72
  196. data/spec/unit/htty/cli/display_spec.rb +0 -84
  197. data/spec/unit/htty/cli_spec.rb +0 -28
  198. data/spec/unit/htty/command.rb +0 -47
  199. data/spec/unit/htty/headers_spec.rb +0 -40
  200. data/spec/unit/htty/payload_spec.rb +0 -60
  201. data/spec/unit/htty/preferences_spec.rb +0 -8
  202. data/spec/unit/htty/request_follow_spec.rb +0 -94
  203. data/spec/unit/htty/request_spec.rb +0 -1232
  204. data/spec/unit/htty/request_userinfo_spec.rb +0 -208
  205. data/spec/unit/htty/response_spec.rb +0 -0
  206. data/spec/unit/htty/session_spec.rb +0 -10
  207. data/spec/unit/htty/shared_examples_for_requests.rb +0 -32
  208. data/spec/unit/htty/url_escaping.rb +0 -70
  209. data/spec/unit/htty/version_spec.rb +0 -8
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/cli")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
4
-
5
- describe HTTY::CLI do
6
- describe 'with empty arguments' do
7
- let :cli do
8
- HTTY::CLI.new([])
9
- end
10
-
11
- it 'should have a session with the URI http://0.0.0.0:80/' do
12
- cli.session.requests.should == [HTTY::Request.new('http://0.0.0.0:80/')]
13
- end
14
- end
15
-
16
- describe 'with an address argument' do
17
- let :cli do
18
- HTTY::CLI.new(%w(https://njonsson@github.com/njonsson/htty))
19
- end
20
-
21
- it 'should have a session with a URI corresponding to the address' do
22
- cli.session.requests.should == [HTTY::Request.new('https://' +
23
- 'njonsson@github.com' +
24
- ':443' +
25
- '/njonsson/htty')]
26
- end
27
- end
28
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/cli/command")
4
-
5
- describe HTTY::CLI::Command do
6
- let(:last_request) {HTTY::Request.new('http://0.0.0.0')}
7
- let(:requests) {[last_request]}
8
- let(:session) do
9
- session = double
10
- session.stub(:requests) {requests}
11
- session
12
- end
13
-
14
- subject{described_class.new(:session => session)}
15
-
16
- describe '#add_request_if_new' do
17
- context 'when command returns nil' do
18
- it 'should not add the request' do
19
- expect do
20
- subject.send(:add_request_if_new) do
21
- nil
22
- end
23
- end.to_not change{subject.session.requests.count}
24
- end
25
- end
26
-
27
- context 'when command returns the same request' do
28
- it 'should not add the request' do
29
- expect do
30
- subject.send(:add_request_if_new) do
31
- last_request
32
- end
33
- end.to_not change{subject.session.requests.count}
34
- end
35
- end
36
-
37
- context 'when command returns a different request' do
38
- it 'should add the request' do
39
- expect do
40
- subject.send(:add_request_if_new) do
41
- HTTY::Request.new('http://0.0.0.0/foo')
42
- end
43
- end.to change{subject.session.requests.count}.by(1)
44
- end
45
- end
46
- end
47
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/headers")
3
-
4
- describe HTTY::Headers do
5
- describe 'that is empty' do
6
- it { should be_empty }
7
-
8
- describe 'when values are added out of order' do
9
- before :each do
10
- subject['foo'] = 'bar'
11
- subject['baz'] = 'qux'
12
- end
13
-
14
- it { should == {'foo' => 'bar', 'baz' => 'qux'} }
15
-
16
- it 'should return the expected array when sent #to_a' do
17
- subject.to_a.should == [%w(foo bar), %w(baz qux)]
18
- end
19
- end
20
- end
21
-
22
- describe 'that has values out of order' do
23
- subject { described_class.new('foo' => 'bar', 'baz' => 'qux') }
24
-
25
- it { should == {'foo' => 'bar', 'baz' => 'qux'} }
26
-
27
- it 'should index the values as expected' do
28
- subject['foo'].should == 'bar'
29
- subject['baz'].should == 'qux'
30
- end
31
-
32
- describe 'when sent #clear' do
33
- before :each do
34
- subject.clear
35
- end
36
-
37
- it { should be_empty }
38
- end
39
- end
40
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/payload")
3
-
4
-
5
- describe HTTY::Payload do
6
- before(:all) do
7
- @bare_payload = Class.new(HTTY::Payload)
8
- end
9
-
10
- let(:body) {nil}
11
- let(:headers) {[['Accept', 'application/json']]}
12
-
13
- subject {@bare_payload.new({:body => body, :headers => headers})}
14
-
15
- it 'should heave headers' do
16
- subject.should have(1).headers
17
- end
18
-
19
- describe '.headers(key)' do
20
- it 'should be case insensitive' do
21
- subject.headers_with_key('Accept').should == [['Accept', 'application/json']]
22
- subject.headers_with_key('Accept').should == subject.headers_with_key('accept')
23
- end
24
- end
25
-
26
- describe '.header(key)' do
27
- it 'should return the header with a given key' do
28
- subject.header('Accept').should == 'application/json'
29
- end
30
-
31
- it 'should return the header with a given key ignoring the case' do
32
- ['Accept', 'ACCEPT', 'accept', 'AccEpT'].each do |key|
33
- subject.header(key).should == 'application/json'
34
- end
35
- end
36
-
37
- context 'when key is not found' do
38
- it 'should raise an exception' do
39
- expect do
40
- subject.header('not-found-key')
41
- end.to raise_error(HTTY::NoHeaderError)
42
- end
43
-
44
- context 'when given a value as second parameter' do
45
- it 'should return the default value' do
46
- subject.header('not-found-key', :default).should == :default
47
- end
48
- end
49
-
50
- context 'when given an exception' do
51
- it 'should raise that exception' do
52
- exception_to_raise = Exception.new('key not found')
53
- expect do
54
- subject.header('not-found-key', exception_to_raise)
55
- end.to raise_error(exception_to_raise.class)
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/preferences")
3
-
4
- describe HTTY::Preferences do
5
- it 'should maintain current preferences' do
6
- HTTY::Preferences.current.should == HTTY::Preferences.current
7
- end
8
- end
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/response")
4
-
5
-
6
- describe HTTY::Request do
7
- let(:request_address) {'http://example.com/a?b=c#d'}
8
- let(:request) {HTTY::Request.new request_address}
9
-
10
- describe '#follow a response' do
11
- let(:response) do
12
- HTTY::Response.new({:headers => {'Location' => response_location}})
13
- end
14
-
15
- before :each do
16
- request.send :response=, response
17
- end
18
-
19
- describe 'with an absolute URI in Location header' do
20
- let(:response_location) {'http://followme.com/a/b/c'}
21
-
22
- it 'should return another request' do
23
- request.follow(response).should_not == request
24
- end
25
-
26
- it 'should return a request with the absolute URI as its HTTP URI' do
27
- request.follow(response).uri.should == URI.parse(response_location)
28
- end
29
- end
30
-
31
- describe 'with an absolute path in Location header' do
32
- let(:response_location) {'/a/b/c'}
33
-
34
- it 'should return a request with the same URI host ' +
35
- 'and with the URI path changed to the absolute path in Location' do
36
- expected_uri = URI.parse(request_address)
37
- expected_uri.path = response_location
38
- expected_uri.query = nil
39
- expected_uri.fragment = nil
40
- request.follow(response).uri.should == expected_uri
41
- end
42
- end
43
-
44
- describe 'with a relative path in Location header' do
45
- let(:response_location) {'a/b/c'}
46
-
47
- it 'should return a request with the same URI host ' +
48
- 'and with the URI path changed joining the ' +
49
- 'original URI path to the relative path in Location' do
50
- expected_uri = URI.parse(request_address)
51
- expected_uri.path = File.join(expected_uri.path, response_location)
52
- expected_uri.query = nil
53
- expected_uri.fragment = nil
54
- request.follow(response).uri.should == expected_uri
55
- end
56
-
57
- context 'when invoked more than once' do
58
- let(:after_follow) {request.follow(response)}
59
-
60
- it 'should return always the same request' do
61
- after_follow.uri.should == after_follow.follow(response).uri
62
- end
63
- end
64
- end
65
-
66
- describe 'with an URI with query string in Location header' do
67
- let(:response_location) {'a/b/c?d=e&f=g'}
68
-
69
- it 'should return a request with URI query string ' +
70
- 'equal to the Location query string' do
71
- expected_query = URI.parse(response_location).query
72
- request.follow(response).uri.query.should == expected_query
73
- end
74
-
75
- it 'should return a request without URI fragment' do
76
- request.follow(response).uri.fragment.should be_nil
77
- end
78
- end
79
-
80
- describe 'with an URI with fragment in Location header' do
81
- let(:response_location) {'a/b/c#f'}
82
-
83
- it 'should return a request with URI fragment ' +
84
- 'equal to the Location fragment' do
85
- expected_fragment = URI.parse(response_location).fragment
86
- request.follow(response).uri.fragment.should == expected_fragment
87
- end
88
-
89
- it 'should return a request without URI query string' do
90
- request.follow(response).uri.query.should be_nil
91
- end
92
- end
93
- end
94
- end
@@ -1,1232 +0,0 @@
1
- require 'spec_helper'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/response")
4
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/version")
5
-
6
- require File.expand_path("#{File.dirname __FILE__}/shared_examples_for_requests")
7
-
8
- describe HTTY::Request do
9
- let(:username) {'njonsson'}
10
- let(:password) {nil}
11
-
12
- describe 'initializing with' do
13
- let :klass do
14
- HTTY::Request
15
- end
16
-
17
- describe 'a valid FTP address' do
18
- it 'should raise URI::InvalidURIError' do
19
- expect do
20
- klass.new 'ftp://myftpsite.info'
21
- end.to raise_error(ArgumentError,
22
- 'only http:// and https:// schemes are supported')
23
- end
24
- end
25
- end
26
-
27
- describe 'with a nil address' do
28
- let :request do
29
- HTTY::Request.new nil
30
- end
31
-
32
- it 'should have the URI http://0.0.0.0:80/' do
33
- request.uri.should == URI.parse('http://0.0.0.0:80/')
34
- end
35
-
36
- it_should_behave_like 'an empty request'
37
- end
38
-
39
- describe 'with an empty address' do
40
- let :request do
41
- HTTY::Request.new ''
42
- end
43
-
44
- it 'should have the URI http://0.0.0.0:80/' do
45
- request.uri.should == URI.parse('http://0.0.0.0:80/')
46
- end
47
-
48
- it_should_behave_like 'an empty request'
49
- end
50
-
51
- describe 'with an address consisting of' do
52
- describe 'an IPv4 address' do
53
- let :request do
54
- HTTY::Request.new '127.0.0.1'
55
- end
56
-
57
- it 'should have an HTTP URI for that host' do
58
- request.uri.should == URI.parse('http://127.0.0.1:80/')
59
- end
60
-
61
- it_should_behave_like 'an empty request'
62
- end
63
-
64
- describe 'a hostname' do
65
- let :request do
66
- HTTY::Request.new 'localhost'
67
- end
68
-
69
- it 'should have HTTP URI for that host' do
70
- request.uri.should == URI.parse('http://localhost:80/')
71
- end
72
-
73
- it_should_behave_like 'an empty request'
74
-
75
- describe '-- when sent #query_set' do
76
- describe 'with a query parameter --' do
77
- before :each do
78
- request.query_set 'foo', 'bar'
79
- end
80
-
81
- it 'should have a URI including the query parameter' do
82
- request.uri.should == URI.parse('http://localhost:80/?foo=bar')
83
- end
84
-
85
- it_should_behave_like 'an empty request'
86
- end
87
- end
88
- end
89
-
90
- describe 'a hostname and a port' do
91
- let :request do
92
- HTTY::Request.new 'localhost:8080'
93
- end
94
-
95
- it 'should have an HTTP URI for that host on that port' do
96
- request.uri.should == URI.parse('http://localhost:8080/')
97
- end
98
-
99
- it_should_behave_like 'an empty request'
100
- end
101
-
102
- describe 'the HTTP scheme and a hostname' do
103
- let :request do
104
- HTTY::Request.new 'http://localhost'
105
- end
106
-
107
- it 'should have an HTTP URI for that host' do
108
- request.uri.should == URI.parse('http://localhost:80/')
109
- end
110
-
111
- it_should_behave_like 'an empty request'
112
- end
113
-
114
- describe 'the HTTPS scheme, userinfo, and a hostname' do
115
- let :request do
116
- HTTY::Request.new 'https://njonsson@github.com'
117
- end
118
-
119
- it 'should have an HTTPS URI for host with that userinfo' do
120
- request.uri.should == URI.parse('https://njonsson@github.com:443/')
121
- end
122
-
123
- it_should_behave_like 'an empty, authenticated request'
124
- end
125
-
126
- describe 'a hostname and the root path' do
127
- let :request do
128
- HTTY::Request.new 'github.com/'
129
- end
130
-
131
- it 'should have an HTTP URI for the root of that host' do
132
- request.uri.should == URI.parse('http://github.com:80/')
133
- end
134
-
135
- it_should_behave_like 'an empty request'
136
- end
137
-
138
- describe 'a hostname, port 443, and the root path' do
139
- let :request do
140
- HTTY::Request.new 'github.com:443/'
141
- end
142
-
143
- it 'should have an HTTPS URI for the root of that host' do
144
- request.uri.should == URI.parse('https://github.com:443/')
145
- end
146
-
147
- it_should_behave_like 'an empty request'
148
- end
149
-
150
- describe 'the HTTP scheme, a hostname, port 443, and the root path' do
151
- let :request do
152
- HTTY::Request.new 'http://github.com:443/'
153
- end
154
-
155
- it 'should have an HTTP URI for the root of that host on port 443' do
156
- request.uri.should == URI.parse('http://github.com:443/')
157
- end
158
-
159
- it_should_behave_like 'an empty request'
160
- end
161
-
162
- describe 'a hostname and a path' do
163
- let :request do
164
- HTTY::Request.new 'github.com/explore'
165
- end
166
-
167
- it 'should have an HTTP URI for that path on that host' do
168
- request.uri.should == URI.parse('http://github.com:80/explore')
169
- end
170
-
171
- it_should_behave_like 'an empty request'
172
- end
173
-
174
- describe 'a hostname and a query string' do
175
- let :request do
176
- HTTY::Request.new 'github.com?search=http'
177
- end
178
-
179
- it 'should have an HTTP URI for that query string and the root of ' +
180
- 'that host' do
181
- request.uri.should == URI.parse('http://github.com:80/?search=http')
182
- end
183
-
184
- it_should_behave_like 'an empty request'
185
- end
186
-
187
- describe 'a hostname, a path, and a query string' do
188
- let :request do
189
- HTTY::Request.new 'github.com/search?q=http&lang=en'
190
- end
191
-
192
- it 'should have an HTTP URI for that query string and that path on ' +
193
- 'that host' do
194
- request.uri.should == URI.parse('http://github.com:80' +
195
- '/search?q=http&lang=en')
196
- end
197
-
198
- it_should_behave_like 'an empty request'
199
- end
200
-
201
- describe 'a hostname, a path, and a fragment' do
202
- let :request do
203
- HTTY::Request.new 'github.com/explore#trending'
204
- end
205
-
206
- it 'should have an HTTP URI for that fragment of that path on that ' +
207
- 'host' do
208
- request.uri.should == URI.parse('http://github.com:80/explore#trending')
209
- end
210
-
211
- it_should_behave_like 'an empty request'
212
- end
213
-
214
- describe 'a hostname, a port, a path, a query string, and a fragment' do
215
- let :request do
216
- HTTY::Request.new 'github.com:123/search/deep?q=http&lang=en#content'
217
- end
218
-
219
- it 'should have an HTTP URI for that query string and that fragment ' +
220
- 'of that path on that host on that port' do
221
- request.uri.should == URI.parse('http://github.com:123' +
222
- '/search/deep?q=http&lang=en' +
223
- '#content')
224
- end
225
-
226
- it_should_behave_like 'an empty request'
227
- end
228
-
229
- describe 'the HTTPS scheme, userinfo, a hostname, a port, a path, a ' +
230
- 'query string, and a fragment' do
231
- let :request do
232
- HTTY::Request.new 'https://njonsson@github.com:123' +
233
- '/search/deep?q=http&lang=en#content'
234
- end
235
-
236
- describe 'and without a response' do
237
- it 'should not have a response' do
238
- request.response.should be_nil
239
- end
240
-
241
- describe '-- and is untouched --' do
242
- it 'should have an HTTPS URI for that query string and that ' +
243
- 'fragment of that path on that host on that port with that ' +
244
- 'userinfo' do
245
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
246
- '/search/deep?q=http&lang=en' +
247
- '#content')
248
- end
249
-
250
- it_should_behave_like 'an empty, authenticated request'
251
- end
252
-
253
- describe '-- when sent #address with an address consisting of' do
254
- describe 'the HTTP scheme and different userinfo, hostname, port, ' +
255
- 'path, query string, and fragment --' do
256
- before :each do
257
- request.address 'http://steve@mac.com:456/archives/2010' +
258
- '?author=jobs&subject=html5#flames'
259
- end
260
-
261
- it 'should have an HTTP URI for the new query string and the new ' +
262
- 'fragment of the new path on the new host on the new port ' +
263
- 'with the new userinfo' do
264
- request.uri.should == URI.parse('http://steve@mac.com:456' +
265
- '/archives/2010' +
266
- '?author=jobs&subject=html5' +
267
- '#flames')
268
- end
269
-
270
- it 'should the expected Authorization header plus the default ' +
271
- 'headers' do
272
- request.headers.should == [['User-Agent', 'htty/' +
273
- HTTY::VERSION],
274
- ['Authorization', 'Basic c3RldmU=']]
275
- end
276
-
277
- it 'should have no body' do
278
- request.body.should be_nil
279
- end
280
-
281
- it 'should have no response' do
282
- request.response.should be_nil
283
- end
284
- end
285
-
286
- describe 'a different hostname --' do
287
- before :each do
288
- request.address 'mac.com'
289
- end
290
-
291
- it 'should have an HTTP URI for the new host' do
292
- request.uri.should == URI.parse('http://mac.com:80/')
293
- end
294
-
295
- it_should_behave_like 'an empty request'
296
- end
297
- end
298
-
299
- describe '-- when sent #scheme_set with' do
300
- describe 'the same scheme --' do
301
- before :each do
302
- request.scheme_set 'https'
303
- end
304
-
305
- it 'should have an unchanged URI' do
306
- request.uri.should == URI.parse('https://njonsson@github.com' +
307
- ':123' +
308
- '/search/deep?q=http&lang=en' +
309
- '#content')
310
- end
311
-
312
- it_should_behave_like 'an empty, authenticated request'
313
- end
314
-
315
- describe 'a different scheme --' do
316
- before :each do
317
- request.scheme_set 'http'
318
- end
319
-
320
- it 'should have the same URI, with the changed scheme' do
321
- request.uri.should == URI.parse('http://njonsson@github.com' +
322
- ':123' +
323
- '/search/deep?q=http&lang=en' +
324
- '#content')
325
- end
326
-
327
- it_should_behave_like 'an empty, authenticated request'
328
- end
329
- end
330
-
331
- describe '-- when sent #host_set with' do
332
- describe 'the same host --' do
333
- before :each do
334
- request.host_set 'github.com'
335
- end
336
-
337
- it 'should have an unchanged URI' do
338
- request.uri.should == URI.parse('https://njonsson@github.com' +
339
- ':123' +
340
- '/search/deep?q=http&lang=en' +
341
- '#content')
342
- end
343
-
344
- it_should_behave_like 'an empty, authenticated request'
345
- end
346
-
347
- describe 'a different host --' do
348
- before :each do
349
- request.host_set 'gist.github.com'
350
- end
351
-
352
- it 'should have the same URI, with the changed scheme' do
353
- request.uri.should == URI.parse('https://' +
354
- 'njonsson@gist.github.com:123' +
355
- '/search/deep?q=http&lang=en' +
356
- '#content')
357
- end
358
-
359
- it_should_behave_like 'an empty, authenticated request'
360
- end
361
- end
362
-
363
- describe '-- when sent #port_set with' do
364
- describe 'the same port --' do
365
- before :each do
366
- request.port_set 123
367
- end
368
-
369
- it 'should have an unchanged URI' do
370
- request.uri.should == URI.parse('https://njonsson@github.com' +
371
- ':123' +
372
- '/search/deep?q=http&lang=en' +
373
- '#content')
374
- end
375
-
376
- it_should_behave_like 'an empty, authenticated request'
377
- end
378
-
379
- describe 'a different port --' do
380
- before :each do
381
- request.port_set 8888
382
- end
383
-
384
- it 'should have the same URI, with the changed scheme' do
385
- request.uri.should == URI.parse('https://njonsson@github.com' +
386
- ':8888' +
387
- '/search/deep?q=http&lang=en' +
388
- '#content')
389
- end
390
-
391
- it_should_behave_like 'an empty, authenticated request'
392
- end
393
- end
394
-
395
- describe '-- when sent #path_set with a path consisting of' do
396
- describe 'a child reference --' do
397
- before :each do
398
- request.path_set 'foo'
399
- end
400
-
401
- it 'should have the same URI, descending to the expected path' do
402
- request.uri.should == URI.parse('https://njonsson@github.com' +
403
- ':123' +
404
- '/search/deep/foo' +
405
- '?q=http&lang=en#content')
406
- end
407
-
408
- it_should_behave_like 'an empty, authenticated request'
409
- end
410
-
411
- describe 'a parent reference --' do
412
- before :each do
413
- request.path_set '..'
414
- end
415
-
416
- it 'should have the same URI, ascending to the expected path' do
417
- request.uri.should == URI.parse('https://njonsson@github.com' +
418
- ':123' +
419
- '/search?q=http&lang=en#content')
420
- end
421
-
422
- it_should_behave_like 'an empty, authenticated request'
423
- end
424
-
425
- describe 'an absolute reference --' do
426
- before :each do
427
- request.path_set '/foo/bar'
428
- end
429
-
430
- it 'should have the same URI, changing to the expected path' do
431
- request.uri.should == URI.parse('https://njonsson@github.com' +
432
- ':123' +
433
- '/foo/bar?q=http&lang=en' +
434
- '#content')
435
- end
436
-
437
- it_should_behave_like 'an empty, authenticated request'
438
- end
439
- end
440
-
441
- describe '-- when sent #query_set' do
442
- describe 'with a new query parameter --' do
443
- before :each do
444
- request.query_set 'foo', 'bar'
445
- end
446
-
447
- it 'should have a URI including the new query parameter' do
448
- request.uri.should == URI.parse('https://njonsson@github.com' +
449
- ':123' +
450
- '/search/deep' +
451
- '?q=http&lang=en&foo=bar' +
452
- '#content')
453
- end
454
-
455
- it_should_behave_like 'an empty, authenticated request'
456
- end
457
-
458
- describe 'with a new value for the first query parameter --' do
459
- before :each do
460
- request.query_set 'q', 'ruby'
461
- end
462
-
463
- it 'should have a URI with the new value of the query parameter' do
464
- request.uri.should == URI.parse('https://njonsson@github.com' +
465
- ':123' +
466
- '/search/deep?q=ruby&lang=en' +
467
- '#content')
468
- end
469
-
470
- it_should_behave_like 'an empty, authenticated request'
471
- end
472
-
473
- describe 'with a new value for the second query parameter --' do
474
- before :each do
475
- request.query_set 'lang', 'fr'
476
- end
477
-
478
- it 'should have a URI with the new value of the second query ' +
479
- 'parameter' do
480
- request.uri.should == URI.parse('https://njonsson@github.com' +
481
- ':123' +
482
- '/search/deep?q=http&lang=fr' +
483
- '#content')
484
- end
485
-
486
- it_should_behave_like 'an empty, authenticated request'
487
- end
488
- end
489
-
490
- describe '-- when sent #query_unset' do
491
- describe 'with a nonexistent query parameter --' do
492
- before :each do
493
- request.query_unset 'fizzle'
494
- end
495
-
496
- it 'should have an unchanged URI' do
497
- request.uri.should == URI.parse('https://njonsson@github.com' +
498
- ':123' +
499
- '/search/deep?q=http&lang=en' +
500
- '#content')
501
- end
502
-
503
- it_should_behave_like 'an empty, authenticated request'
504
- end
505
-
506
- describe 'with the first query parameter --' do
507
- before :each do
508
- request.query_unset 'q'
509
- end
510
-
511
- it 'should have a URI missing the first query parameter' do
512
- request.uri.should == URI.parse('https://njonsson@github.com' +
513
- ':123' +
514
- '/search/deep?lang=en#content')
515
- end
516
-
517
- it_should_behave_like 'an empty, authenticated request'
518
- end
519
-
520
- describe 'with the second query parameter --' do
521
- before :each do
522
- request.query_unset 'lang'
523
- end
524
-
525
- it 'should have a URI missing the second query parameter' do
526
- request.uri.should == URI.parse('https://njonsson@github.com' +
527
- ':123' +
528
- '/search/deep?q=http#content')
529
- end
530
-
531
- it_should_behave_like 'an empty, authenticated request'
532
- end
533
- end
534
-
535
- describe '-- when sent #query_unset_all --' do
536
- before :each do
537
- request.query_unset_all
538
- end
539
-
540
- it 'should have a URI having no query string' do
541
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
542
- '/search/deep#content')
543
- end
544
-
545
- it_should_behave_like 'an empty, authenticated request'
546
- end
547
-
548
- describe '-- when sent #fragment_set with' do
549
- describe 'the same fragment --' do
550
- before :each do
551
- request.fragment_set 'content'
552
- end
553
-
554
- it 'should have an unchanged URI' do
555
- request.uri.should == URI.parse('https://njonsson@github.com' +
556
- ':123' +
557
- '/search/deep?q=http&lang=en' +
558
- '#content')
559
- end
560
-
561
- it_should_behave_like 'an empty, authenticated request'
562
- end
563
-
564
- describe 'different fragment --' do
565
- before :each do
566
- request.fragment_set 'details'
567
- end
568
-
569
- it 'should have the same URI, with the changed fragment' do
570
- request.uri.should == URI.parse('https://njonsson@github.com' +
571
- ':123' +
572
- '/search/deep?q=http&lang=en' +
573
- '#details')
574
- end
575
-
576
- it_should_behave_like 'an empty, authenticated request'
577
- end
578
- end
579
-
580
- describe '-- when sent #fragment_unset --' do
581
- before :each do
582
- request.fragment_unset
583
- end
584
-
585
- it 'should have the same URI, without fragment' do
586
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
587
- '/search/deep?q=http&lang=en')
588
- end
589
-
590
- it_should_behave_like 'an empty, authenticated request'
591
- end
592
-
593
- describe '-- when sent #header_set with a new header' do
594
- before :each do
595
- request.header_set 'foo', 'bar'
596
- end
597
-
598
- it 'should have an unchanged URI' do
599
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
600
- '/search/deep?q=http&lang=en' +
601
- '#content')
602
- end
603
-
604
- describe '--' do
605
- it 'should have the header, plus the default headers' do
606
- request.headers.should == [['User-Agent', 'htty/' +
607
- HTTY::VERSION],
608
- ['Authorization', 'Basic ' +
609
- 'bmpvbnNzb24='],
610
- ['foo', 'bar']]
611
- end
612
- end
613
-
614
- describe 'and then #header_unset' do
615
- describe 'with the same header name --' do
616
- before :each do
617
- request.header_unset 'foo'
618
- end
619
-
620
- it 'should have only the default headers' do
621
- request.headers.should == [['User-Agent', 'htty/' +
622
- HTTY::VERSION],
623
- ['Authorization', 'Basic ' +
624
- 'bmpvbnNzb24=']]
625
- end
626
- end
627
-
628
- describe 'with a different header name --' do
629
- before :each do
630
- request.header_unset 'qux'
631
- end
632
-
633
- it 'should have the header, plus the default headers' do
634
- request.headers.should == [['User-Agent', 'htty/' +
635
- HTTY::VERSION],
636
- ['Authorization', 'Basic ' +
637
- 'bmpvbnNzb24='],
638
- ['foo', 'bar']]
639
- end
640
- end
641
- end
642
-
643
- describe 'and then #headers_unset_all --' do
644
- before :each do
645
- request.headers_unset_all
646
- end
647
-
648
- it 'should have no headers' do
649
- request.headers.should be_empty
650
- end
651
- end
652
- end
653
-
654
- describe '-- when sent #cookie_add with a cookie' do
655
- before :each do
656
- request.cookie_add 'foo', 'bar'
657
- end
658
-
659
- it 'should have an unchanged URI' do
660
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
661
- '/search/deep?q=http&lang=en' +
662
- '#content')
663
- end
664
-
665
- describe '--' do
666
- it 'should have the cookie' do
667
- request.cookies.should == [%w(foo bar)]
668
- end
669
-
670
- it 'should have the cookie header, plus the default headers' do
671
- request.headers.should == [['User-Agent', 'htty/' +
672
- HTTY::VERSION],
673
- ['Authorization', 'Basic ' +
674
- 'bmpvbnNzb24='],
675
- ['Cookie', 'foo=bar']]
676
- end
677
- end
678
-
679
- describe 'and then #cookie_add' do
680
- describe 'with the same cookie name --' do
681
- before :each do
682
- request.cookie_add 'foo', 'qux'
683
- end
684
-
685
- it 'should have the new cookie, plus the old cookie' do
686
- request.cookies.should == [%w(foo bar), %w(foo qux)]
687
- end
688
-
689
- it 'should have the new cookie header, plus the default ' +
690
- 'headers' do
691
- request.headers.should == [['User-Agent', 'htty/' +
692
- HTTY::VERSION],
693
- ['Authorization', 'Basic ' +
694
- 'bmpvbnNzb24='],
695
- ['Cookie', 'foo=bar; ' +
696
- 'foo=qux']]
697
- end
698
- end
699
-
700
- describe 'with a different cookie name --' do
701
- before :each do
702
- request.cookie_add 'baz', 'qux'
703
- end
704
-
705
- it 'should have the new cookie' do
706
- request.cookies.should == [%w(foo bar), %w(baz qux)]
707
- end
708
-
709
- it 'should have the new cookie header, plus the default ' +
710
- 'headers' do
711
- request.headers.should == [['User-Agent', 'htty/' +
712
- HTTY::VERSION],
713
- ['Authorization', 'Basic ' +
714
- 'bmpvbnNzb24='],
715
- ['Cookie', 'foo=bar; ' +
716
- 'baz=qux']]
717
- end
718
- end
719
-
720
- describe 'with a different cookie name and no value --' do
721
- before :each do
722
- request.cookie_add 'baz'
723
- end
724
-
725
- it 'should have the new cookie' do
726
- request.cookies.should == [['foo', 'bar'], ['baz', nil]]
727
- end
728
-
729
- it 'should have the new cookie header, plus the default ' +
730
- 'headers' do
731
- request.headers.should == [['User-Agent', 'htty/' +
732
- HTTY::VERSION],
733
- ['Authorization', 'Basic ' +
734
- 'bmpvbnNzb24='],
735
- ['Cookie', 'foo=bar; baz']]
736
- end
737
- end
738
- end
739
-
740
- describe 'and then #cookie_remove' do
741
- describe 'with the same cookie name --' do
742
- before :each do
743
- request.cookie_remove 'foo'
744
- end
745
-
746
- it 'should have no cookie' do
747
- request.cookies.should be_empty
748
- end
749
-
750
- it 'should have only the default headers' do
751
- request.headers.should == [['User-Agent', 'htty/' +
752
- HTTY::VERSION],
753
- ['Authorization', 'Basic ' +
754
- 'bmpvbnNzb24=']]
755
- end
756
- end
757
-
758
- describe 'with a different cookie name --' do
759
- before :each do
760
- request.cookie_remove 'qux'
761
- end
762
-
763
- it 'should have the cookie' do
764
- request.cookies.should == [%w(foo bar)]
765
- end
766
-
767
- it 'should have the cookie header, plus the default headers' do
768
- request.headers.should == [['User-Agent', 'htty/' +
769
- HTTY::VERSION],
770
- ['Authorization', 'Basic ' +
771
- 'bmpvbnNzb24='],
772
- ['Cookie', 'foo=bar']]
773
- end
774
- end
775
- end
776
-
777
- describe 'and then #cookies_remove_all --' do
778
- before :each do
779
- request.cookies_remove_all
780
- end
781
-
782
- it 'should have no cookies' do
783
- request.cookies.should be_empty
784
- end
785
-
786
- it 'should have only the default headers' do
787
- request.headers.should == [['User-Agent', 'htty/' +
788
- HTTY::VERSION],
789
- ['Authorization', 'Basic ' +
790
- 'bmpvbnNzb24=']]
791
- end
792
- end
793
-
794
- describe 'and then #address' do
795
- describe 'with the same host --' do
796
- before :each do
797
- request.address 'http://github.com'
798
- end
799
-
800
- it 'should have the cookie' do
801
- request.cookies.should == [%w(foo bar)]
802
- end
803
-
804
- it 'should have the cookie header, plus the default headers' do
805
- request.headers.should == [['User-Agent', 'htty/' +
806
- HTTY::VERSION],
807
- ['Cookie', 'foo=bar']]
808
- end
809
- end
810
-
811
- describe 'with a different host --' do
812
- before :each do
813
- request.address 'http://google.com'
814
- end
815
-
816
- it 'should have no cookies' do
817
- request.cookies.should == []
818
- request.cookies.should be_empty
819
- end
820
-
821
- it 'should have only the default headers' do
822
- request.headers.should == [['User-Agent',
823
- "htty/#{HTTY::VERSION}"]]
824
- end
825
- end
826
- end
827
- end
828
-
829
- describe "-- when sent #cookie_add with a new cookie containing '='" do
830
- before :each do
831
- request.cookie_add 'foo', 'bar=baz=qux'
832
- end
833
-
834
- describe '--' do
835
- it 'should have the cookie' do
836
- request.cookies.should == [%w(foo bar=baz=qux)]
837
- end
838
-
839
- it 'should have the cookie header, plus the default headers' do
840
- request.headers.should == [['User-Agent', 'htty/' +
841
- HTTY::VERSION],
842
- ['Authorization', 'Basic ' +
843
- 'bmpvbnNzb24='],
844
- ['Cookie', 'foo=bar=baz=qux']]
845
- end
846
- end
847
- end
848
-
849
- describe '-- when sent #body_set with a body' do
850
- before :each do
851
- request.body_set 'foo'
852
- end
853
-
854
- it 'should have an unchanged URI' do
855
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
856
- '/search/deep?q=http&lang=en' +
857
- '#content')
858
- end
859
-
860
- describe '--' do
861
- it 'should have the body' do
862
- request.body.should == 'foo'
863
- end
864
-
865
- it 'should have only the default headers' do
866
- request.headers.should == [['User-Agent', 'htty/' +
867
- HTTY::VERSION],
868
- ['Authorization', 'Basic ' +
869
- 'bmpvbnNzb24=']]
870
- end
871
-
872
- it "should have the expected 'Content-Length' header, plus the " +
873
- "'User-Agent' header if we do not exclude the " +
874
- "'Content-Length' header" do
875
- request.headers(true).should == [['User-Agent', 'htty/' +
876
- HTTY::VERSION],
877
- ['Authorization', 'Basic ' +
878
- 'bmpvbnNz' +
879
- 'b24='],
880
- ['Content-Length', '3']]
881
- end
882
- end
883
-
884
- describe 'and then #body_unset' do
885
- before :each do
886
- request.body_unset
887
- end
888
-
889
- it 'should have no body' do
890
- request.body.should be_nil
891
- end
892
-
893
- it 'should have only the default headers' do
894
- request.headers.should == [['User-Agent', 'htty/' +
895
- HTTY::VERSION],
896
- ['Authorization', 'Basic ' +
897
- 'bmpvbnNzb24=']]
898
- end
899
- end
900
- end
901
- end
902
-
903
- describe 'and with a response' do
904
- let :response do
905
- HTTY::Response.new
906
- end
907
-
908
- before :each do
909
- request.send :response=, response
910
- end
911
-
912
- it 'should not affect the URI' do
913
- request.uri.should == URI.parse('https://njonsson@github.com:123' +
914
- '/search/deep?q=http&lang=en' +
915
- '#content')
916
- end
917
-
918
- it 'should not affect the headers' do
919
- request.headers.should == [['User-Agent', 'htty/' +
920
- HTTY::VERSION],
921
- ['Authorization', 'Basic ' +
922
- 'bmpvbnNzb24=']]
923
- end
924
-
925
- it 'should not affect the body' do
926
- request.body.should be_nil
927
- end
928
-
929
- it 'should not affect the response' do
930
- request.response.should == response
931
- end
932
-
933
- describe '-- when sent #address with a different hostname --' do
934
- let :new_request do
935
- request.address 'mac.com'
936
- end
937
-
938
- it 'should return a request with an HTTP URI for the new host' do
939
- new_request.uri.should == URI.parse('http://mac.com:80/')
940
- end
941
-
942
- it 'should return a request without a response' do
943
- new_request.response.should be_nil
944
- end
945
- end
946
-
947
- describe '-- when sent #scheme_set with a different scheme --' do
948
- let :new_request do
949
- request.scheme_set 'http'
950
- end
951
-
952
- it 'should return a request with the same URI having the changed ' +
953
- 'scheme' do
954
- new_request.uri.should == URI.parse('http://njonsson@github.com' +
955
- ':123' +
956
- '/search/deep?q=http&lang=en' +
957
- '#content')
958
- end
959
-
960
- it 'should return a request without a response' do
961
- new_request.response.should be_nil
962
- end
963
- end
964
-
965
- describe '-- when sent #host_set with a different host --' do
966
- let :new_request do
967
- request.host_set 'gist.github.com'
968
- end
969
-
970
- it 'should return a request with the same URI having the changed ' +
971
- 'host' do
972
- new_request.uri.should == URI.parse('https://' +
973
- 'njonsson@gist.github.com' +
974
- ':123' +
975
- '/search/deep?q=http&lang=en' +
976
- '#content')
977
- end
978
-
979
- it 'should return a request without a response' do
980
- new_request.response.should be_nil
981
- end
982
- end
983
-
984
- describe '-- when sent #port_set with a different port --' do
985
- let :new_request do
986
- request.port_set 8888
987
- end
988
-
989
- it 'should return a request with the same URI having the changed ' +
990
- 'port' do
991
- new_request.uri.should == URI.parse('https://njonsson@github.com' +
992
- ':8888' +
993
- '/search/deep?q=http&lang=en' +
994
- '#content')
995
- end
996
-
997
- it 'should return a request without a response' do
998
- new_request.response.should be_nil
999
- end
1000
- end
1001
-
1002
- describe '-- when sent #path_set with a different path --' do
1003
- let :new_request do
1004
- request.path_set 'foo'
1005
- end
1006
-
1007
- it 'should return a request with the same URI having the changed ' +
1008
- 'path' do
1009
- new_request.uri.should == URI.parse('https://njonsson@github.com' +
1010
- ':123' +
1011
- '/search/deep/foo' +
1012
- '?q=http&lang=en#content')
1013
- end
1014
-
1015
- it 'should return a request without a response' do
1016
- new_request.response.should be_nil
1017
- end
1018
- end
1019
-
1020
- describe '-- when sent #query_set with a query parameter --' do
1021
- let :new_request do
1022
- request.query_set 'foo', 'bar'
1023
- end
1024
-
1025
- it 'should return a request with the same URI having the new query ' +
1026
- 'parameter' do
1027
- new_request.uri.should == URI.parse('https://njonsson@github.com' +
1028
- ':123' +
1029
- '/search/deep' +
1030
- '?q=http&lang=en&foo=bar' +
1031
- '#content')
1032
- end
1033
-
1034
- it 'should return a request without a response' do
1035
- new_request.response.should be_nil
1036
- end
1037
- end
1038
-
1039
- describe '-- when sent #query_unset with the first query ' +
1040
- 'parameter --' do
1041
- let :new_request do
1042
- request.query_unset 'q'
1043
- end
1044
-
1045
- it 'should return a request with the same URI missing the first ' +
1046
- 'query parameter' do
1047
- new_request.uri.should == URI.parse('https://njonsson@github.com' +
1048
- ':123' +
1049
- '/search/deep?lang=en#content')
1050
- end
1051
-
1052
- it 'should return a request without a response' do
1053
- new_request.response.should be_nil
1054
- end
1055
- end
1056
-
1057
- describe '-- when sent #query_unset_all --' do
1058
- let :new_request do
1059
- request.query_unset_all
1060
- end
1061
-
1062
- it 'should return a request with the same URI having no query ' +
1063
- 'string' do
1064
- new_request.uri.should == URI.parse('https://' +
1065
- 'njonsson@github.com:123' +
1066
- '/search/deep#content')
1067
- end
1068
-
1069
- it 'should return a request without a response' do
1070
- new_request.response.should be_nil
1071
- end
1072
- end
1073
-
1074
- describe '-- when sent #fragment_set with a different fragment --' do
1075
- let :new_request do
1076
- request.fragment_set 'details'
1077
- end
1078
-
1079
- it 'should return a request with the same URI having the changed ' +
1080
- 'fragment' do
1081
- new_request.uri.should == URI.parse('https://njonsson@github.com' +
1082
- ':123' +
1083
- '/search/deep?q=http&lang=en' +
1084
- '#details')
1085
- end
1086
-
1087
- it 'should return a request without a response' do
1088
- new_request.response.should be_nil
1089
- end
1090
- end
1091
-
1092
- describe '-- when sent #fragment_unset --' do
1093
- let :new_request do
1094
- request.fragment_unset
1095
- end
1096
-
1097
- it 'should return a request with the same URI missing the fragment' do
1098
- new_request.uri.should == URI.parse('https://' +
1099
- 'njonsson@github.com:123' +
1100
- '/search/deep?q=http&lang=en')
1101
- end
1102
-
1103
- it 'should return a request without a response' do
1104
- new_request.response.should be_nil
1105
- end
1106
- end
1107
-
1108
- describe '-- when sent #header_set with a new header' do
1109
- let :new_request do
1110
- request.header_set 'foo', 'bar'
1111
- end
1112
-
1113
- it 'should return a request with an unchanged URI' do
1114
- new_request.uri.should == URI.parse('https://' +
1115
- 'njonsson@github.com:123' +
1116
- '/search/deep?q=http&lang=en' +
1117
- '#content')
1118
- end
1119
-
1120
- it 'should return a request with no response' do
1121
- new_request.response.should be_nil
1122
- end
1123
-
1124
- describe '--' do
1125
- it 'should return a request with the header, plus the default ' +
1126
- 'headers' do
1127
- new_request.headers.should == [['User-Agent', 'htty/' +
1128
- HTTY::VERSION],
1129
- ['Authorization', 'Basic ' +
1130
- 'bmpvbnNzb24='],
1131
- ['foo', 'bar']]
1132
- end
1133
-
1134
- it 'should return a request without a response' do
1135
- new_request.response.should be_nil
1136
- end
1137
- end
1138
-
1139
- describe 'and then #header_unset' do
1140
- describe 'with the same header name --' do
1141
- let :new_request do
1142
- request.header_unset 'foo'
1143
- end
1144
-
1145
- it 'should return a request with only the default headers' do
1146
- new_request.headers.should == [['User-Agent', 'htty/' +
1147
- HTTY::VERSION],
1148
- ['Authorization', 'Basic ' +
1149
- 'bmpvbnNzb2' +
1150
- '4=']]
1151
- end
1152
- end
1153
- end
1154
-
1155
- describe 'and then #headers_unset_all --' do
1156
- let :new_request do
1157
- request.headers_unset_all
1158
- end
1159
-
1160
- it 'should return a request with no headers' do
1161
- new_request.headers.should be_empty
1162
- end
1163
- end
1164
- end
1165
-
1166
- describe '-- when sent #body_set with a body' do
1167
- let :new_request do
1168
- request.body_set 'foo'
1169
- end
1170
-
1171
- it 'should return a request with an unchanged URI' do
1172
- new_request.uri.should == URI.parse('https://' +
1173
- 'njonsson@github.com:123' +
1174
- '/search/deep?q=http&lang=en' +
1175
- '#content')
1176
- end
1177
-
1178
- it 'should return a request with no response' do
1179
- new_request.response.should be_nil
1180
- end
1181
-
1182
- describe '--' do
1183
- it 'should return a request with the body' do
1184
- new_request.body.should == 'foo'
1185
- end
1186
-
1187
- it 'should return a request with only the default headers' do
1188
- new_request.headers.should == [['User-Agent', 'htty/' +
1189
- HTTY::VERSION],
1190
- ['Authorization', 'Basic ' +
1191
- 'bmpvbnNzb2' +
1192
- '4=']]
1193
- end
1194
-
1195
- it "should return a request with the expected 'Content-Length' " +
1196
- "header, plus the 'User-Agent' header if we do not exclude " +
1197
- "the 'Content-Length' header" do
1198
- new_request.headers(true).should == [['User-Agent', 'htty/' +
1199
- HTTY::VERSION],
1200
- ['Authorization', 'Basic ' +
1201
- 'bmpvbn' +
1202
- 'Nzb24='],
1203
- ['Content-Length', '3']]
1204
- end
1205
-
1206
- it 'should return a request without a response' do
1207
- new_request.response.should be_nil
1208
- end
1209
- end
1210
-
1211
- describe 'and then #body_unset' do
1212
- let :new_request do
1213
- request.body_unset
1214
- end
1215
-
1216
- it 'should return a request with no body' do
1217
- new_request.body.should be_nil
1218
- end
1219
-
1220
- it 'should return a request with only the default headers' do
1221
- new_request.headers.should == [['User-Agent', 'htty/' +
1222
- HTTY::VERSION],
1223
- ['Authorization', 'Basic ' +
1224
- 'bmpvbnNzb2' +
1225
- '4=']]
1226
- end
1227
- end
1228
- end
1229
- end
1230
- end
1231
- end
1232
- end