htty 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +46 -0
- data/README.markdown +12 -12
- data/VERSION +1 -1
- data/lib/htty/cli.rb +10 -0
- data/lib/htty/cli/command.rb +50 -41
- data/lib/htty/cli/commands/http_put.rb +3 -0
- data/lib/htty/cli/commands/query_unset.rb +4 -2
- data/lib/htty/cli/http_method_command.rb +5 -3
- data/spec/integration/htty/cli/commands/query_add_spec.rb +51 -0
- data/spec/integration/htty/cli/commands/query_remove_spec.rb +37 -0
- data/spec/integration/htty/cli/commands/query_set_spec.rb +72 -0
- data/spec/integration/htty/cli/commands/query_unset_spec.rb +37 -0
- data/spec/unit/htty/cli/commands/address_spec.rb +103 -0
- data/spec/unit/htty/cli/commands/body_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/body_request_spec.rb +72 -0
- data/spec/unit/htty/cli/commands/body_response_spec.rb +70 -0
- data/spec/unit/htty/cli/commands/body_set_spec.rb +71 -0
- data/spec/unit/htty/cli/commands/body_unset_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/cd_spec.rb +57 -0
- data/spec/unit/htty/cli/commands/cookie_add_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/cookies_add_spec.rb +78 -0
- data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/cookies_spec.rb +76 -0
- data/spec/unit/htty/cli/commands/cookies_use_spec.rb +75 -0
- data/spec/unit/htty/cli/commands/delete_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/exit_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/follow_spec.rb +70 -0
- data/spec/unit/htty/cli/commands/form_add_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/form_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +66 -0
- data/spec/unit/htty/cli/commands/form_remove_spec.rb +57 -0
- data/spec/unit/htty/cli/commands/form_spec.rb +57 -0
- data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/fragment_set_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +72 -0
- data/spec/unit/htty/cli/commands/get_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/header_set_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/header_unset_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/headers_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/headers_request_spec.rb +81 -0
- data/spec/unit/htty/cli/commands/headers_response_spec.rb +77 -0
- data/spec/unit/htty/cli/commands/headers_set_spec.rb +74 -0
- data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +71 -0
- data/spec/unit/htty/cli/commands/headers_unset_spec.rb +63 -0
- data/spec/unit/htty/cli/commands/help_spec.rb +67 -0
- data/spec/unit/htty/cli/commands/history_spec.rb +65 -0
- data/spec/unit/htty/cli/commands/history_verbose_spec.rb +72 -0
- data/spec/unit/htty/cli/commands/host_set_spec.rb +71 -0
- data/spec/unit/htty/cli/commands/http_delete_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/http_get_spec.rb +75 -0
- data/spec/unit/htty/cli/commands/http_head_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/http_options_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/http_post_spec.rb +71 -0
- data/spec/unit/htty/cli/commands/http_put_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/http_trace_spec.rb +69 -0
- data/spec/unit/htty/cli/commands/path_set_spec.rb +72 -0
- data/spec/unit/htty/cli/commands/port_set_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/post_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/put_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/query_add_spec.rb +67 -36
- data/spec/unit/htty/cli/commands/query_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/query_remove_spec.rb +69 -24
- data/spec/unit/htty/cli/commands/query_set_spec.rb +59 -49
- data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/query_unset_spec.rb +75 -0
- data/spec/unit/htty/cli/commands/quit_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/reuse_spec.rb +72 -0
- data/spec/unit/htty/cli/commands/scheme_set_spec.rb +74 -0
- data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +67 -0
- data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +60 -0
- data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +65 -0
- data/spec/unit/htty/cli/commands/status_spec.rb +73 -0
- data/spec/unit/htty/cli/commands/undo_spec.rb +57 -0
- data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +64 -0
- data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +75 -0
- data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +72 -0
- data/spec/unit/htty/cli_spec.rb +8 -2
- data/spec/unit/htty/ordered_hash_spec.rb +14 -24
- data/spec/unit/htty/preferences_spec.rb +1 -1
- data/spec/unit/htty/request_spec.rb +454 -463
- metadata +80 -20
data/History.markdown
CHANGED
@@ -1,6 +1,52 @@
|
|
1
1
|
Version history for the _htty_ project
|
2
2
|
======================================
|
3
3
|
|
4
|
+
v1.2.0, Wed 12/01/2010
|
5
|
+
---------------------
|
6
|
+
|
7
|
+
* Added support for Tab-key completion of user input [[carsonmcdonald](http://github.com/carsonmcdonald "carsonmcdonald at GitHub")]
|
8
|
+
* Enhanced the `query-unset` command to accept an optional _value_ argument [[mattsa](http://github.com/mattsa "mattsa at GitHub")]
|
9
|
+
|
10
|
+
v1.1.6, Mon 11/22/2010
|
11
|
+
---------------------
|
12
|
+
|
13
|
+
* Added the `query-add` and `query-remove` commands [[mattsa](http://github.com/mattsa "mattsa at GitHub")]:
|
14
|
+
* Added context-sensitive help in connection with server certificate verification
|
15
|
+
* Upgraded various dependencies
|
16
|
+
|
17
|
+
v1.1.5, Wed 10/20/2010
|
18
|
+
---------------------
|
19
|
+
|
20
|
+
* Added the `ssl-verification*` commands for controlling the verification of server certificates [[dtjm](http://github.com/dtjm "dtjm at GitHub")]
|
21
|
+
* Fixed a bug in the `query-set` command [[mattsa](http://github.com/mattsa "mattsa at GitHub")]
|
22
|
+
* Fixed a Ruby < v1.9 compatibility problem
|
23
|
+
|
24
|
+
v1.1.4, Sat 10/16/2010
|
25
|
+
---------------------
|
26
|
+
|
27
|
+
* Enhanced the `query-set` command [[mattsa](http://github.com/mattsa "mattsa at GitHub")] to:
|
28
|
+
- Accept an arbitrary number of arguments
|
29
|
+
- Support valueless keys
|
30
|
+
- Support duplicate keys
|
31
|
+
- Support keys with brackets in their names, à la Rails
|
32
|
+
|
33
|
+
v1.1.3, Tue 10/12/2010
|
34
|
+
---------------------
|
35
|
+
|
36
|
+
* Fixed a bug in the arrow keys and Emacs key bindings support within the `body-set` command [ephox-rob/[rojotek](http://github.com/rojotek "rojotek at GitHub")]
|
37
|
+
* Fixed a bug involving empty response bodies such as are received with _304 Not Modified_
|
38
|
+
|
39
|
+
v1.1.2, Wed 9/29/2010
|
40
|
+
---------------------
|
41
|
+
|
42
|
+
* Stopped recording blank and repeated entries in the command history [[jgorset](http://github.com/jgorset "jgorset at GitHub")]
|
43
|
+
* Fixed a bug in the help index
|
44
|
+
|
45
|
+
v1.1.1, Tue 9/28/2010
|
46
|
+
---------------------
|
47
|
+
|
48
|
+
* Classified RubyGems for building documentation as development-only dependencies
|
49
|
+
|
4
50
|
v1.1.0, Tue 9/28/2010
|
5
51
|
---------------------
|
6
52
|
|
data/README.markdown
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
|____| |____| / ______|
|
28
28
|
\/
|
29
29
|
|
30
|
-
[htty](http://htty.github.com) is a console application for interacting with HTTP servers. It’s something of a cross between
|
30
|
+
[htty](http://htty.github.com) is a console application for interacting with HTTP servers. It’s something of a cross between [cURL](http://curl.haxx.se) and a browser.
|
31
31
|
|
32
32
|
See what’s changed lately by reading the [project history](http://htty.github.com/file.History.html). [![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](http://flattr.com/thing/68277/htty-the-HTTP-TTY "Flattr this")
|
33
33
|
|
@@ -43,7 +43,7 @@ You’ll need Ruby and RubyGems. It’s known to work well under OS X against Ru
|
|
43
43
|
Features
|
44
44
|
========
|
45
45
|
|
46
|
-
* Intuitive commands and command aliases
|
46
|
+
* Intuitive, Tab-completed commands and command aliases
|
47
47
|
* Support for familiar HTTP methods _GET_, _POST_, _PUT_, and _DELETE_, as well as _HEAD_, _OPTIONS_ and _TRACE_
|
48
48
|
* Support for HTTP Secure connections and HTTP Basic Authentication
|
49
49
|
* Automatic URL-encoding of userinfo, paths, query-string parameters, and page fragments
|
@@ -159,8 +159,8 @@ Type `body-set` to enter body data, and terminate it by typing Return three time
|
|
159
159
|
Different response codes are rendered with colors that suggest their meaning:
|
160
160
|
|
161
161
|
* Response codes between 200 and 299 appear <span style="background-color: green; color: black; font-weight: bold; padding: 0 0.25em 0 0.25em;">black on green</span> to indicate success
|
162
|
-
* Response codes between 300 and 399 appear <span style="background-color:
|
163
|
-
* Response codes between 400 and 499 appear <span style="background-color:
|
162
|
+
* Response codes between 300 and 399 appear <span style="background-color: darkblue; color: white; font-weight: bold; padding: 0 0.25em 0 0.25em;">white on blue</span> to indicate redirection
|
163
|
+
* Response codes between 400 and 499 appear <span style="background-color: darkred; color: white; font-weight: bold; padding: 0 0.25em 0 0.25em;">white on red</span> to indicate failure
|
164
164
|
* Response codes between 500 and 599 appear <span style="background-color: yellow; color: black; font-weight: bold; padding: 0 0.25em 0 0.25em; text-decoration: blink;">flashing black on yellow</span> to indicate a server error
|
165
165
|
|
166
166
|
![Sinatra application example #2](http://htty.github.com/images/sinatra2.png)
|
@@ -196,11 +196,6 @@ Using any of the forthcoming `form` commands will clear any non-form content in
|
|
196
196
|
|
197
197
|
You will also be able to pop open a browser window containing request and response bodies.
|
198
198
|
|
199
|
-
Shiny autocomplete goodness
|
200
|
-
---------------------------
|
201
|
-
|
202
|
-
We’ll have command command autocompletion, and possibly also Tab key navigation of forms.
|
203
|
-
|
204
199
|
Custom command aliases and shell emulation of _http-console_
|
205
200
|
------------------------------------------------------------
|
206
201
|
|
@@ -227,10 +222,15 @@ Credits [![Flattr this](http://api.flattr.com/button/button-compact-static-100x1
|
|
227
222
|
|
228
223
|
The author, [Nils Jonsson](mailto:htty@nilsjonsson.com), owes a debt of inspiration to the [_http-console_](http://github.com/cloudhead/http-console) project.
|
229
224
|
|
230
|
-
Thanks to contributors:
|
225
|
+
Thanks to [contributors](https://github.com/htty/htty/contributors "htty contributors at GitHub") (in alphabetical order):
|
231
226
|
|
232
|
-
*
|
233
|
-
*
|
227
|
+
* Rob Dawson (ephox-rob/[rojotek](https://github.com/rojotek "rojotek at GitHub"))
|
228
|
+
* Bo Frederiksen ([bofrede](https://github.com/bofrede "bofrede at GitHub"))
|
229
|
+
* Johannes Gorset ([jgorset](https://github.com/jgorset "jgorset at GitHub"))
|
230
|
+
* Carson McDonald ([carsonmcdonald](https://github.com/carsonmcdonald "carsonmcdonald at GitHub"))
|
231
|
+
* Sam Nguyen ([dtjm](https://github.com/dtjm "dtjm at GitHub"))
|
232
|
+
* Robert Pitts ([rbxbx](https://github.com/rbxbx "rbxbx at GitHub"))
|
233
|
+
* Matt Sanders ([mattsa](https://github.com/mattsa "mattsa at GitHub"))
|
234
234
|
|
235
235
|
License
|
236
236
|
=======
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/htty/cli.rb
CHANGED
@@ -23,6 +23,7 @@ class HTTY::CLI
|
|
23
23
|
end
|
24
24
|
HTTY::Session.new(everything_but_options.first)
|
25
25
|
end
|
26
|
+
register_completion_proc
|
26
27
|
end
|
27
28
|
|
28
29
|
# Takes over stdin, stdout, and stderr to expose #session to command-line
|
@@ -79,6 +80,15 @@ private
|
|
79
80
|
HTTY::CLI::Commands.build_for command_line, :session => session
|
80
81
|
end
|
81
82
|
|
83
|
+
def register_completion_proc
|
84
|
+
Readline.completion_proc = proc do |input|
|
85
|
+
autocomplete_list = HTTY::CLI::Commands.select do |c|
|
86
|
+
c.complete_for? input
|
87
|
+
end
|
88
|
+
autocomplete_list.collect(&:raw_name)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
82
92
|
def repeat?(command_line)
|
83
93
|
command_line == Readline::HISTORY.to_a[-2]
|
84
94
|
end
|
data/lib/htty/cli/command.rb
CHANGED
@@ -84,6 +84,13 @@ class HTTY::CLI::Command
|
|
84
84
|
nil
|
85
85
|
end
|
86
86
|
|
87
|
+
# Returns +true+ if the specified _command_line_ can be autocompleted to the
|
88
|
+
# command.
|
89
|
+
def self.complete_for?(command_line)
|
90
|
+
command_name = command_line_for_class_name(name)
|
91
|
+
command_name[0...command_line.length] == command_line
|
92
|
+
end
|
93
|
+
|
87
94
|
# Returns the help text for the command.
|
88
95
|
def self.help
|
89
96
|
return "Alias for #{strong alias_for.command_line}" if alias_for
|
@@ -96,25 +103,10 @@ class HTTY::CLI::Command
|
|
96
103
|
"#{help}."
|
97
104
|
end
|
98
105
|
|
99
|
-
# Returns
|
100
|
-
|
101
|
-
|
102
|
-
name
|
103
|
-
if container.nil?
|
104
|
-
container = instance_eval("::#{element}", __FILE__, __LINE__)
|
105
|
-
else
|
106
|
-
container = container.module_eval(element, __FILE__, __LINE__)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Returns an array of the constants that share this command's namespace.
|
112
|
-
def self.namespace_siblings
|
113
|
-
namespace = namespaces.last
|
114
|
-
other_commands = namespace.constants.collect do |constant|
|
115
|
-
type = namespace.module_eval(constant.to_s, __FILE__, __LINE__)
|
116
|
-
(type == self) ? nil : type
|
117
|
-
end.compact
|
106
|
+
# Returns the full name of the command as it appears on the command line,
|
107
|
+
# without abbreviations.
|
108
|
+
def self.raw_name
|
109
|
+
command_line_for_class_name name
|
118
110
|
end
|
119
111
|
|
120
112
|
# Returns related command classes for the command.
|
@@ -135,10 +127,49 @@ protected
|
|
135
127
|
|
136
128
|
private
|
137
129
|
|
130
|
+
def self.command_line_for_class_name(class_name)
|
131
|
+
class_name.split('::').last.gsub(/(.)([A-Z])/, '\1-\2').downcase
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.completion_optional(text)
|
135
|
+
return nil if text.empty?
|
136
|
+
char_length = (text[0..0] == '\\') ? 2 : 1
|
137
|
+
rest = (text.length > char_length) ?
|
138
|
+
completion_optional(text[char_length..-1]) :
|
139
|
+
nil
|
140
|
+
"(?:#{text[0...char_length]}#{rest})?"
|
141
|
+
end
|
142
|
+
|
138
143
|
def self.cookies?(request)
|
139
144
|
!request.cookies.empty?
|
140
145
|
end
|
141
146
|
|
147
|
+
def self.make_command_line_regexp
|
148
|
+
pattern = Regexp.escape(command_line).gsub(/\\\[(.+)\\\]/) do |optional|
|
149
|
+
completion_optional($1)
|
150
|
+
end
|
151
|
+
Regexp.new "^#{pattern}(\\s.+)?$", Regexp::IGNORECASE
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.namespaces
|
155
|
+
container = nil
|
156
|
+
name.split('::')[0...-1].collect do |element|
|
157
|
+
if container.nil?
|
158
|
+
container = instance_eval("::#{element}", __FILE__, __LINE__)
|
159
|
+
else
|
160
|
+
container = container.module_eval(element, __FILE__, __LINE__)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.namespace_siblings
|
166
|
+
namespace = namespaces.last
|
167
|
+
other_commands = namespace.constants.collect do |constant|
|
168
|
+
type = namespace.module_eval(constant.to_s, __FILE__, __LINE__)
|
169
|
+
(type == self) ? nil : type
|
170
|
+
end.compact
|
171
|
+
end
|
172
|
+
|
142
173
|
public
|
143
174
|
|
144
175
|
# Returns the arguments provided to the command.
|
@@ -182,26 +213,4 @@ protected
|
|
182
213
|
self
|
183
214
|
end
|
184
215
|
|
185
|
-
private
|
186
|
-
|
187
|
-
def self.command_line_for_class_name(class_name)
|
188
|
-
class_name.split('::').last.gsub(/(.)([A-Z])/, '\1-\2').downcase
|
189
|
-
end
|
190
|
-
|
191
|
-
def self.completion_optional(text)
|
192
|
-
return nil if text.empty?
|
193
|
-
char_length = (text[0..0] == '\\') ? 2 : 1
|
194
|
-
rest = (text.length > char_length) ?
|
195
|
-
completion_optional(text[char_length..-1]) :
|
196
|
-
nil
|
197
|
-
"(?:#{text[0...char_length]}#{rest})?"
|
198
|
-
end
|
199
|
-
|
200
|
-
def self.make_command_line_regexp
|
201
|
-
pattern = Regexp.escape(command_line).gsub(/\\\[(.+)\\\]/) do |optional|
|
202
|
-
completion_optional($1)
|
203
|
-
end
|
204
|
-
Regexp.new "^#{pattern}(\\s.+)?$", Regexp::IGNORECASE
|
205
|
-
end
|
206
|
-
|
207
216
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/../http_method_command")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/http_get")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/http_post")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/http_delete")
|
3
6
|
|
4
7
|
module HTTY; end
|
5
8
|
|
@@ -26,7 +26,7 @@ class HTTY::CLI::Commands::QueryUnset < HTTY::CLI::Command
|
|
26
26
|
# Returns the arguments for the command-line usage of the _query-unset_
|
27
27
|
# command.
|
28
28
|
def self.command_line_arguments
|
29
|
-
'NAME'
|
29
|
+
'NAME [VALUE]'
|
30
30
|
end
|
31
31
|
|
32
32
|
# Returns the help text for the _query-unset_ command.
|
@@ -63,7 +63,9 @@ class HTTY::CLI::Commands::QueryUnset < HTTY::CLI::Command
|
|
63
63
|
def perform
|
64
64
|
add_request_if_has_response do |request|
|
65
65
|
self.class.notify_if_cookies_cleared request do
|
66
|
-
|
66
|
+
unset_method = (arguments.length == 2) ? :query_remove : :query_unset
|
67
|
+
request.send(unset_method,
|
68
|
+
*escape_or_warn_of_escape_sequences(arguments))
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
require File.expand_path("#{File.dirname __FILE__}/../request")
|
2
1
|
require File.expand_path("#{File.dirname __FILE__}/display")
|
3
|
-
require
|
4
|
-
require File.expand_path("#{File.dirname __FILE__}
|
2
|
+
# TODO: See if we can avoid circular references without omitting these 'require' statements
|
3
|
+
# require File.expand_path("#{File.dirname __FILE__}/../request")
|
4
|
+
# require File.expand_path("#{File.dirname __FILE__}/commands/cookies_use")
|
5
|
+
# require File.expand_path("#{File.dirname __FILE__}/commands/follow")
|
6
|
+
# require File.expand_path("#{File.dirname __FILE__}/commands/ssl_verification_off")
|
5
7
|
|
6
8
|
module HTTY; end
|
7
9
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
|
4
|
+
|
5
|
+
describe HTTY::CLI::Commands::QueryAdd do
|
6
|
+
let :klass do
|
7
|
+
subject.class
|
8
|
+
end
|
9
|
+
|
10
|
+
let :session do
|
11
|
+
HTTY::Session.new nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance(*arguments)
|
15
|
+
klass.new :session => session, :arguments => arguments
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with key argument only' do
|
19
|
+
describe 'without key already present' do
|
20
|
+
it 'should add key' do
|
21
|
+
instance('test').perform
|
22
|
+
session.requests.last.uri.query.should == 'test'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'with key already present' do
|
27
|
+
it 'should add key' do
|
28
|
+
session.requests.last.uri.query = 'test=true'
|
29
|
+
instance('test').perform
|
30
|
+
session.requests.last.uri.query.should == 'test=true&test'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'with key and value arguments' do
|
36
|
+
describe 'without key already present' do
|
37
|
+
it 'should add key and value' do
|
38
|
+
instance('test', 'true').perform
|
39
|
+
session.requests.last.uri.query.should == 'test=true'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'with key already present' do
|
44
|
+
it 'should add key and value' do
|
45
|
+
session.requests.last.uri.query = 'test=true'
|
46
|
+
instance('test', 'false').perform
|
47
|
+
session.requests.last.uri.query.should == 'test=true&test=false'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
|
4
|
+
|
5
|
+
describe HTTY::CLI::Commands::QueryRemove do
|
6
|
+
let :klass do
|
7
|
+
subject.class
|
8
|
+
end
|
9
|
+
|
10
|
+
let :session do
|
11
|
+
HTTY::Session.new nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance(*arguments)
|
15
|
+
klass.new :session => session, :arguments => arguments
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with existing query string with duplicate keys set' do
|
19
|
+
before :each do
|
20
|
+
session.requests.last.uri.query = 'test=true&test=false'
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'with only key specified' do
|
24
|
+
it 'should remove last entry' do
|
25
|
+
instance('test').perform
|
26
|
+
session.requests.last.uri.query.should == 'test=true'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with key and value specified' do
|
31
|
+
it 'should remove matching entry only' do
|
32
|
+
instance('test', 'true').perform
|
33
|
+
session.requests.last.uri.query.should == 'test=false'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
|
4
|
+
|
5
|
+
describe HTTY::CLI::Commands::QuerySet do
|
6
|
+
let :klass do
|
7
|
+
subject.class
|
8
|
+
end
|
9
|
+
|
10
|
+
let :session do
|
11
|
+
HTTY::Session.new nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance(*arguments)
|
15
|
+
klass.new :session => session, :arguments => arguments
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with one argument' do
|
19
|
+
it 'should assign a single key' do
|
20
|
+
instance('test').perform
|
21
|
+
session.requests.last.uri.query.should == 'test'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'with two arguments' do
|
26
|
+
it 'should assign a key-value pair' do
|
27
|
+
instance('test', 'true').perform
|
28
|
+
session.requests.last.uri.query.should == 'test=true'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'with three arguments' do
|
33
|
+
it 'should assign a key-value pair and a valueless key' do
|
34
|
+
instance('test', 'true', 'more').perform
|
35
|
+
session.requests.last.uri.query.should == 'test=true&more'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'with four arguments' do
|
40
|
+
it 'should assign two key-value pairs' do
|
41
|
+
instance('test', 'true', 'more', 'false').perform
|
42
|
+
session.requests.last.uri.query.should == 'test=true&more=false'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'with duplicate keys' do
|
47
|
+
it 'should replace existing key' do
|
48
|
+
session.requests.last.uri.query = 'test=true'
|
49
|
+
instance('test', 'false').perform
|
50
|
+
session.requests.last.uri.query.should == 'test=false'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should maintain field location' do
|
54
|
+
session.requests.last.uri.query = 'test=true&more=true'
|
55
|
+
instance('test', 'false').perform
|
56
|
+
session.requests.last.uri.query.should == 'test=false&more=true'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should replace multiple instances with one' do
|
60
|
+
session.requests.last.uri.query = 'test=true&more=true&test=true'
|
61
|
+
instance('test', 'false').perform
|
62
|
+
session.requests.last.uri.query.should == 'test=false&more=true'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should play nice with nested fields' do
|
66
|
+
session.requests.last.uri.query = 'test[my][]=1'
|
67
|
+
instance('test[my][]', '2').perform
|
68
|
+
instance('test', '3').perform
|
69
|
+
session.requests.last.uri.query.should == 'test[my][]=2&test=3'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|