htty 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/htty/cli/commands/address.rb +1 -1
- data/lib/htty/cli/commands/cookies_add.rb +1 -1
- data/lib/htty/cli/commands/cookies_remove.rb +1 -1
- data/lib/htty/cli/commands/fragment_set.rb +1 -1
- data/lib/htty/cli/commands/headers_set.rb +1 -1
- data/lib/htty/cli/commands/headers_unset.rb +1 -1
- data/lib/htty/cli/commands/help.rb +1 -1
- data/lib/htty/cli/commands/host_set.rb +1 -1
- data/lib/htty/cli/commands/path_set.rb +1 -1
- data/lib/htty/cli/commands/port_set.rb +1 -1
- data/lib/htty/cli/commands/query_add.rb +74 -0
- data/lib/htty/cli/commands/query_remove.rb +72 -0
- data/lib/htty/cli/commands/query_set.rb +13 -16
- data/lib/htty/cli/commands/query_unset.rb +17 -8
- data/lib/htty/cli/commands/reuse.rb +1 -1
- data/lib/htty/cli/commands/scheme_set.rb +1 -1
- data/lib/htty/cli/commands/userinfo_set.rb +1 -1
- data/lib/htty/cli/http_method_command.rb +12 -1
- data/lib/htty/request.rb +41 -5
- data/spec/system/scenarios_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_add_spec.rb +51 -0
- data/spec/unit/htty/cli/commands/query_remove_spec.rb +37 -0
- data/spec/unit/htty/cli/commands/query_set_spec.rb +3 -2
- data/spec/unit/htty/cli_spec.rb +1 -1
- data/spec/unit/htty/ordered_hash_spec.rb +1 -1
- data/spec/unit/htty/preferences_spec.rb +1 -1
- data/spec/unit/htty/request_spec.rb +1 -1
- data/spec/unit/htty/session_spec.rb +1 -1
- data/spec/unit/htty_spec.rb +1 -1
- metadata +8 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.6
|
@@ -24,7 +24,7 @@ class HTTY::CLI::Commands::Address < HTTY::CLI::Command
|
|
24
24
|
|
25
25
|
# Returns the arguments for the command-line usage of the _address_ command.
|
26
26
|
def self.command_line_arguments
|
27
|
-
'
|
27
|
+
'ADDRESS'
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns the help text for the _address_ command.
|
@@ -22,7 +22,7 @@ class HTTY::CLI::Commands::CookiesAdd < HTTY::CLI::Command
|
|
22
22
|
# Returns the arguments for the command-line usage of the _cookies-add_
|
23
23
|
# command.
|
24
24
|
def self.command_line_arguments
|
25
|
-
'
|
25
|
+
'NAME [VALUE]'
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns the help text for the _cookies-add_ command.
|
@@ -22,7 +22,7 @@ class HTTY::CLI::Commands::CookiesRemove < HTTY::CLI::Command
|
|
22
22
|
# Returns the arguments for the command-line usage of the _cookies-remove_
|
23
23
|
# command.
|
24
24
|
def self.command_line_arguments
|
25
|
-
'
|
25
|
+
'NAME'
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns the help text for the _cookies-remove_ command.
|
@@ -22,7 +22,7 @@ class HTTY::CLI::Commands::FragmentSet < HTTY::CLI::Command
|
|
22
22
|
|
23
23
|
# Returns the arguments for the command-line usage of the _fragment-set_ command.
|
24
24
|
def self.command_line_arguments
|
25
|
-
'
|
25
|
+
'FRAGMENT'
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns the help text for the _fragment-set_ command.
|
@@ -21,7 +21,7 @@ class HTTY::CLI::Commands::HeadersSet < HTTY::CLI::Command
|
|
21
21
|
# Returns the arguments for the command-line usage of the _headers-set_
|
22
22
|
# command.
|
23
23
|
def self.command_line_arguments
|
24
|
-
'
|
24
|
+
'NAME VALUE'
|
25
25
|
end
|
26
26
|
|
27
27
|
# Returns the help text for the _headers-set_ command.
|
@@ -21,7 +21,7 @@ class HTTY::CLI::Commands::HeadersUnset < HTTY::CLI::Command
|
|
21
21
|
# Returns the arguments for the command-line usage of the _headers-unset_
|
22
22
|
# command.
|
23
23
|
def self.command_line_arguments
|
24
|
-
'
|
24
|
+
'NAME'
|
25
25
|
end
|
26
26
|
|
27
27
|
# Returns the help text for the _headers-unset_ command.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../url_escaping")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/address")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/query_remove")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/query_set")
|
6
|
+
require File.expand_path("#{File.dirname __FILE__}/query_unset")
|
7
|
+
require File.expand_path("#{File.dirname __FILE__}/query_unset_all")
|
8
|
+
|
9
|
+
module HTTY; end
|
10
|
+
|
11
|
+
class HTTY::CLI; end
|
12
|
+
|
13
|
+
module HTTY::CLI::Commands; end
|
14
|
+
|
15
|
+
# Encapsulates the _query-add_ command.
|
16
|
+
class HTTY::CLI::Commands::QueryAdd < HTTY::CLI::Command
|
17
|
+
|
18
|
+
include HTTY::CLI::Display
|
19
|
+
include HTTY::CLI::UrlEscaping
|
20
|
+
|
21
|
+
# Returns the name of a category under which help for the _query-add_ command
|
22
|
+
# should appear.
|
23
|
+
def self.category
|
24
|
+
'Navigation'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the arguments for the command-line usage of the _query-add_ command.
|
28
|
+
def self.command_line_arguments
|
29
|
+
'NAME [VALUE [NAME [VALUE ...]]]'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the help text for the _query-add_ command.
|
33
|
+
def self.help
|
34
|
+
"Adds query-string parameters to the request's address"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the extended help text for the _query-add_ command.
|
38
|
+
def self.help_extended
|
39
|
+
'Adds one or more query-string parameters used for the request. Does not ' +
|
40
|
+
"communicate with the host.\n" +
|
41
|
+
"\n" +
|
42
|
+
'The difference between this command and ' +
|
43
|
+
"#{strong HTTY::CLI::Commands::QuerySet.command_line} is that this " +
|
44
|
+
"command adds duplicate parameters instead of replacing any of them.\n" +
|
45
|
+
"\n" +
|
46
|
+
'The name(s) and value(s) of the query-string parameter(s) will be URL-' +
|
47
|
+
"encoded if necessary.\n" +
|
48
|
+
"\n" +
|
49
|
+
'The console prompt shows the address for the current request.'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns related command classes for the _query-add_ command.
|
53
|
+
def self.see_also_commands
|
54
|
+
[HTTY::CLI::Commands::QueryRemove,
|
55
|
+
HTTY::CLI::Commands::QuerySet,
|
56
|
+
HTTY::CLI::Commands::QueryUnset,
|
57
|
+
HTTY::CLI::Commands::QueryUnsetAll,
|
58
|
+
HTTY::CLI::Commands::Address]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Performs the _query-add_ command.
|
62
|
+
def perform
|
63
|
+
add_request_if_has_response do |request|
|
64
|
+
self.class.notify_if_cookies_cleared request do
|
65
|
+
escaped_arguments = escape_or_warn_of_escape_sequences(arguments)
|
66
|
+
escaped_arguments.each_slice 2 do |name, value|
|
67
|
+
request.query_add name, value
|
68
|
+
end
|
69
|
+
request
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../url_escaping")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/address")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/query_add")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/query_set")
|
6
|
+
require File.expand_path("#{File.dirname __FILE__}/query_unset")
|
7
|
+
require File.expand_path("#{File.dirname __FILE__}/query_unset_all")
|
8
|
+
|
9
|
+
module HTTY; end
|
10
|
+
|
11
|
+
class HTTY::CLI; end
|
12
|
+
|
13
|
+
module HTTY::CLI::Commands; end
|
14
|
+
|
15
|
+
# Encapsulates the _query-remove_ command.
|
16
|
+
class HTTY::CLI::Commands::QueryRemove < HTTY::CLI::Command
|
17
|
+
|
18
|
+
include HTTY::CLI::Display
|
19
|
+
include HTTY::CLI::UrlEscaping
|
20
|
+
|
21
|
+
# Returns the name of a category under which help for the _query-remove_
|
22
|
+
# command should appear.
|
23
|
+
def self.category
|
24
|
+
'Navigation'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the arguments for the command-line usage of the _query-remove_
|
28
|
+
# command.
|
29
|
+
def self.command_line_arguments
|
30
|
+
'NAME [VALUE]'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the help text for the _query-remove_ command.
|
34
|
+
def self.help
|
35
|
+
"Removes query-string parameters from the end of the request's address"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the extended help text for the _query-remove_ command.
|
39
|
+
def self.help_extended
|
40
|
+
'Removes one or more a query-string parameters used for the request. ' +
|
41
|
+
"Does not communicate with the host.\n" +
|
42
|
+
"\n" +
|
43
|
+
'The difference between this command and ' +
|
44
|
+
"#{strong HTTY::CLI::Commands::QueryUnset.command_line} is that this " +
|
45
|
+
'command removes matching parameters one at a time from the end of the ' +
|
46
|
+
"address instead of removing all matches.\n" +
|
47
|
+
"\n" +
|
48
|
+
'The name and value of the query-string parameter will be URL-encoded if ' +
|
49
|
+
"necessary.\n" +
|
50
|
+
"\n" +
|
51
|
+
'The console prompt shows the address for the current request.'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns related command classes for the _query-remove_ command.
|
55
|
+
def self.see_also_commands
|
56
|
+
[HTTY::CLI::Commands::QueryAdd,
|
57
|
+
HTTY::CLI::Commands::QuerySet,
|
58
|
+
HTTY::CLI::Commands::QueryUnset,
|
59
|
+
HTTY::CLI::Commands::QueryUnsetAll,
|
60
|
+
HTTY::CLI::Commands::Address]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Performs the _query-remove_ command.
|
64
|
+
def perform
|
65
|
+
add_request_if_has_response do |request|
|
66
|
+
self.class.notify_if_cookies_cleared request do
|
67
|
+
request.query_remove(*escape_or_warn_of_escape_sequences(arguments))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/../url_escaping")
|
3
3
|
require File.expand_path("#{File.dirname __FILE__}/address")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/query_add")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/query_remove")
|
4
6
|
require File.expand_path("#{File.dirname __FILE__}/query_unset")
|
5
7
|
require File.expand_path("#{File.dirname __FILE__}/query_unset_all")
|
6
8
|
|
@@ -13,6 +15,7 @@ module HTTY::CLI::Commands; end
|
|
13
15
|
# Encapsulates the _query-set_ command.
|
14
16
|
class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
15
17
|
|
18
|
+
include HTTY::CLI::Display
|
16
19
|
include HTTY::CLI::UrlEscaping
|
17
20
|
|
18
21
|
# Returns the name of a category under which help for the _query-set_ command
|
@@ -23,7 +26,7 @@ class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
|
23
26
|
|
24
27
|
# Returns the arguments for the command-line usage of the _query-set_ command.
|
25
28
|
def self.command_line_arguments
|
26
|
-
'
|
29
|
+
'NAME [VALUE [NAME [VALUE ...]]]'
|
27
30
|
end
|
28
31
|
|
29
32
|
# Returns the help text for the _query-set_ command.
|
@@ -36,7 +39,11 @@ class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
|
36
39
|
'Sets one or more query-string parameters used for the request. Does not ' +
|
37
40
|
"communicate with the host.\n" +
|
38
41
|
"\n" +
|
39
|
-
'The
|
42
|
+
'The difference between this command and ' +
|
43
|
+
"#{strong HTTY::CLI::Commands::QueryAdd.command_line} is that this " +
|
44
|
+
"command replaces any duplicate parameters instead of adding more.\n" +
|
45
|
+
"\n" +
|
46
|
+
'The name(s) and value(s) of the query-string parameter(s) will be URL-' +
|
40
47
|
"encoded if necessary.\n" +
|
41
48
|
"\n" +
|
42
49
|
'The console prompt shows the address for the current request.'
|
@@ -46,6 +53,8 @@ class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
|
46
53
|
def self.see_also_commands
|
47
54
|
[HTTY::CLI::Commands::QueryUnset,
|
48
55
|
HTTY::CLI::Commands::QueryUnsetAll,
|
56
|
+
HTTY::CLI::Commands::QueryAdd,
|
57
|
+
HTTY::CLI::Commands::QueryRemove,
|
49
58
|
HTTY::CLI::Commands::Address]
|
50
59
|
end
|
51
60
|
|
@@ -54,24 +63,12 @@ class HTTY::CLI::Commands::QuerySet < HTTY::CLI::Command
|
|
54
63
|
add_request_if_has_response do |request|
|
55
64
|
self.class.notify_if_cookies_cleared request do
|
56
65
|
escaped_arguments = escape_or_warn_of_escape_sequences(arguments)
|
57
|
-
|
58
|
-
request.query_set
|
66
|
+
escaped_arguments.each_slice 2 do |name, value|
|
67
|
+
request.query_set name, value
|
59
68
|
end
|
60
69
|
request
|
61
70
|
end
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
65
|
-
private
|
66
|
-
|
67
|
-
def in_groups_of(how_many, source)
|
68
|
-
groups = []
|
69
|
-
source = source.dup
|
70
|
-
(source.length / how_many).times do
|
71
|
-
groups << source.slice!(0, how_many)
|
72
|
-
end
|
73
|
-
groups << source unless source.empty?
|
74
|
-
groups
|
75
|
-
end
|
76
|
-
|
77
74
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../command")
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/../url_escaping")
|
3
3
|
require File.expand_path("#{File.dirname __FILE__}/address")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/query_add")
|
5
|
+
require File.expand_path("#{File.dirname __FILE__}/query_remove")
|
4
6
|
require File.expand_path("#{File.dirname __FILE__}/query_set")
|
5
7
|
require File.expand_path("#{File.dirname __FILE__}/query_unset_all")
|
6
8
|
|
@@ -24,22 +26,27 @@ class HTTY::CLI::Commands::QueryUnset < HTTY::CLI::Command
|
|
24
26
|
# Returns the arguments for the command-line usage of the _query-unset_
|
25
27
|
# command.
|
26
28
|
def self.command_line_arguments
|
27
|
-
'
|
29
|
+
'NAME'
|
28
30
|
end
|
29
31
|
|
30
32
|
# Returns the help text for the _query-unset_ command.
|
31
33
|
def self.help
|
32
|
-
"Removes
|
34
|
+
"Removes query-string parameters from the request's address"
|
33
35
|
end
|
34
36
|
|
35
37
|
# Returns the extended help text for the _query-unset_ command.
|
36
38
|
def self.help_extended
|
37
|
-
'Removes a query-string
|
38
|
-
"communicate with the host.\n"
|
39
|
-
"\n"
|
40
|
-
'The
|
41
|
-
"
|
42
|
-
|
39
|
+
'Removes one or more a query-string parameters used for the request. ' +
|
40
|
+
"Does not communicate with the host.\n" +
|
41
|
+
"\n" +
|
42
|
+
'The difference between this command and ' +
|
43
|
+
"#{strong HTTY::CLI::Commands::QueryRemove.command_line} is that this " +
|
44
|
+
'command removes all matching parameters instead of removing matches one ' +
|
45
|
+
"at a time from the end of the address.\n" +
|
46
|
+
"\n" +
|
47
|
+
'The name of the query-string parameter will be URL-encoded if ' +
|
48
|
+
"necessary.\n" +
|
49
|
+
"\n" +
|
43
50
|
'The console prompt shows the address for the current request.'
|
44
51
|
end
|
45
52
|
|
@@ -47,6 +54,8 @@ class HTTY::CLI::Commands::QueryUnset < HTTY::CLI::Command
|
|
47
54
|
def self.see_also_commands
|
48
55
|
[HTTY::CLI::Commands::QuerySet,
|
49
56
|
HTTY::CLI::Commands::QueryUnsetAll,
|
57
|
+
HTTY::CLI::Commands::QueryAdd,
|
58
|
+
HTTY::CLI::Commands::QueryRemove,
|
50
59
|
HTTY::CLI::Commands::Address]
|
51
60
|
end
|
52
61
|
|
@@ -19,7 +19,7 @@ class HTTY::CLI::Commands::SchemeSet < HTTY::CLI::Command
|
|
19
19
|
|
20
20
|
# Returns the arguments for the command-line usage of the _scheme-set_ command.
|
21
21
|
def self.command_line_arguments
|
22
|
-
'
|
22
|
+
'SCHEME'
|
23
23
|
end
|
24
24
|
|
25
25
|
# Returns the help text for the _scheme-set_ command.
|
@@ -24,7 +24,7 @@ class HTTY::CLI::Commands::UserinfoSet < HTTY::CLI::Command
|
|
24
24
|
# Returns the arguments for the command-line usage of the _userinfo-set_
|
25
25
|
# command.
|
26
26
|
def self.command_line_arguments
|
27
|
-
'
|
27
|
+
'USERNAME [PASSWORD]'
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns the help text for the _userinfo-set_ command.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path("#{File.dirname __FILE__}/../request")
|
2
2
|
require File.expand_path("#{File.dirname __FILE__}/display")
|
3
3
|
require File.expand_path("#{File.dirname __FILE__}/commands/cookies_use")
|
4
|
+
require File.expand_path("#{File.dirname __FILE__}/commands/ssl_verification_off")
|
4
5
|
|
5
6
|
module HTTY; end
|
6
7
|
|
@@ -31,13 +32,23 @@ module HTTY::CLI::HTTPMethodCommand
|
|
31
32
|
# Performs the command.
|
32
33
|
def perform
|
33
34
|
add_request_if_has_response do |request|
|
34
|
-
request = request.send("#{method}!", *arguments)
|
35
35
|
unless body? || request.body.to_s.empty?
|
36
36
|
puts notice("The body of your #{method.to_s.upcase} request is not " +
|
37
37
|
'being sent')
|
38
38
|
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
request = request.send("#{method}!", *arguments)
|
42
|
+
rescue OpenSSL::SSL::SSLError => e
|
43
|
+
puts notice('Type ' +
|
44
|
+
strong(HTTY::CLI::Commands::SslVerificationOff.command_line) +
|
45
|
+
' to ignore SSL warnings and complete the request')
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
|
39
49
|
notify_if_cookies
|
40
50
|
notify_if_follow
|
51
|
+
|
41
52
|
request
|
42
53
|
end
|
43
54
|
show_response session.last_response
|
data/lib/htty/request.rb
CHANGED
@@ -374,8 +374,37 @@ public
|
|
374
374
|
request! :put
|
375
375
|
end
|
376
376
|
|
377
|
-
# Establishes a new #uri
|
378
|
-
#
|
377
|
+
# Establishes a new #uri with an additional query-string parameter specified
|
378
|
+
# by _name_ and _value_. The _value_ is optional.
|
379
|
+
def query_add(name, value=nil)
|
380
|
+
entries = current_query_entries
|
381
|
+
entries << name + (value.nil? ? '' : "=#{value}")
|
382
|
+
new_query = entries.empty? ? nil : entries.join('&')
|
383
|
+
rebuild_uri :query => new_query
|
384
|
+
end
|
385
|
+
|
386
|
+
# Establishes a new #uri, removing the last query-string parameter specified
|
387
|
+
# by _name_ and _value_. The _value_ is optional.
|
388
|
+
#
|
389
|
+
# If there is more than one query-string parameter named _name_, those
|
390
|
+
# parameters matching both _name_ and _value_ (if specified) are removed.
|
391
|
+
def query_remove(name, value=nil)
|
392
|
+
return unless uri.query
|
393
|
+
entries = current_query_entries
|
394
|
+
entries.reverse.each do |entry|
|
395
|
+
if entry =~ field_matcher(name, value)
|
396
|
+
entries.delete(entry)
|
397
|
+
break
|
398
|
+
end
|
399
|
+
end
|
400
|
+
rebuild_uri :query => entries.join('&')
|
401
|
+
end
|
402
|
+
|
403
|
+
# Establishes a new #uri with the specified _value_ for the query-string
|
404
|
+
# parameter specified by _name_. The _value_ is optional.
|
405
|
+
#
|
406
|
+
# If there is more than one query-string parameter named _name_, they are
|
407
|
+
# replaced by a single one with the specified _value_.
|
379
408
|
def query_set(name, value=nil)
|
380
409
|
entries = current_query_entries
|
381
410
|
add_or_replace_field(entries, name, value)
|
@@ -383,8 +412,11 @@ public
|
|
383
412
|
rebuild_uri :query => new_query
|
384
413
|
end
|
385
414
|
|
386
|
-
# Establishes a new #uri
|
415
|
+
# Establishes a new #uri without the query-string parameter specified by
|
387
416
|
# _name_.
|
417
|
+
#
|
418
|
+
# If there is more than one query-string parameter named _name_, they are
|
419
|
+
# removed.
|
388
420
|
def query_unset(name)
|
389
421
|
return unless uri.query
|
390
422
|
entries = current_query_entries
|
@@ -489,9 +521,13 @@ private
|
|
489
521
|
header_set 'Content-Length', body.to_s.length
|
490
522
|
end
|
491
523
|
|
492
|
-
def field_matcher(name)
|
524
|
+
def field_matcher(name, value=nil)
|
493
525
|
escaped = Regexp.escape(name)
|
494
|
-
|
526
|
+
if value
|
527
|
+
Regexp.new "^(#{escaped}\=#{Regexp.escape(value)})$"
|
528
|
+
else
|
529
|
+
Regexp.new "^(#{escaped}|#{escaped}\=.*)$"
|
530
|
+
end
|
495
531
|
end
|
496
532
|
|
497
533
|
def request!(method)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
4
|
+
|
5
|
+
describe HTTY::CLI::Commands::QueryAdd do
|
6
|
+
before :each do
|
7
|
+
@session = HTTY::Session.new('')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'with key argument only' do
|
11
|
+
describe 'without key already present' do
|
12
|
+
it 'should add key' do
|
13
|
+
query_add = create_query_add_and_perform('test')
|
14
|
+
query_add.session.requests.last.uri.query.should == 'test'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with key already present' do
|
19
|
+
it 'should add key' do
|
20
|
+
@session.requests.last.uri.query = 'test=true'
|
21
|
+
query_add = create_query_add_and_perform('test')
|
22
|
+
query_add.session.requests.last.uri.query.should == 'test=true&test'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'with key and value arguments' do
|
28
|
+
describe 'without key already present' do
|
29
|
+
it 'should add key and value' do
|
30
|
+
query_add = create_query_add_and_perform('test', 'true')
|
31
|
+
query_add.session.requests.last.uri.query.should == 'test=true'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'with key already present' do
|
36
|
+
it 'should add key and value' do
|
37
|
+
@session.requests.last.uri.query = 'test=true'
|
38
|
+
query_add = create_query_add_and_perform('test', 'false')
|
39
|
+
query_add.session.requests.last.uri.query.should == 'test=true&test=false'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_query_add_and_perform(*arguments)
|
45
|
+
query_add = HTTY::CLI::Commands::QueryAdd.new(:session => @session,
|
46
|
+
:arguments => arguments)
|
47
|
+
query_add.perform
|
48
|
+
query_add
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
4
|
+
|
5
|
+
describe HTTY::CLI::Commands::QueryRemove do
|
6
|
+
before :each do
|
7
|
+
@session = HTTY::Session.new('')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'with existing query string with duplicate keys set' do
|
11
|
+
before :each do
|
12
|
+
@session.requests.last.uri.query = 'test=true&test=false'
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'with only key specified' do
|
16
|
+
it 'should remove last entry' do
|
17
|
+
query_remove = create_query_remove_and_perform('test')
|
18
|
+
query_remove.session.requests.last.uri.query.should == 'test=true'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with key and value specified' do
|
23
|
+
it 'should remove matching entry only' do
|
24
|
+
query_remove = create_query_remove_and_perform('test', 'true')
|
25
|
+
query_remove.session.requests.last.uri.query.should == 'test=false'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_query_remove_and_perform(*arguments)
|
31
|
+
query_remove = HTTY::CLI::Commands::QueryRemove.new(:session => @session,
|
32
|
+
:arguments => arguments)
|
33
|
+
query_remove.perform
|
34
|
+
query_remove
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli")
|
1
|
+
require 'rspec'
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
|
3
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
|
3
4
|
|
4
5
|
describe HTTY::CLI::Commands::QuerySet do
|
5
6
|
before :all do
|
data/spec/unit/htty/cli_spec.rb
CHANGED
data/spec/unit/htty_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 6
|
10
|
+
version: 1.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nils Jonsson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-22 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -146,7 +146,9 @@ files:
|
|
146
146
|
- lib/htty/cli/commands/port_set.rb
|
147
147
|
- lib/htty/cli/commands/post.rb
|
148
148
|
- lib/htty/cli/commands/put.rb
|
149
|
+
- lib/htty/cli/commands/query_add.rb
|
149
150
|
- lib/htty/cli/commands/query_clear.rb
|
151
|
+
- lib/htty/cli/commands/query_remove.rb
|
150
152
|
- lib/htty/cli/commands/query_set.rb
|
151
153
|
- lib/htty/cli/commands/query_unset.rb
|
152
154
|
- lib/htty/cli/commands/query_unset_all.rb
|
@@ -187,6 +189,8 @@ files:
|
|
187
189
|
- spec/system/scenarios/quit/expected_stdout
|
188
190
|
- spec/system/scenarios/quit/stdin
|
189
191
|
- spec/system/scenarios_spec.rb
|
192
|
+
- spec/unit/htty/cli/commands/query_add_spec.rb
|
193
|
+
- spec/unit/htty/cli/commands/query_remove_spec.rb
|
190
194
|
- spec/unit/htty/cli/commands/query_set_spec.rb
|
191
195
|
- spec/unit/htty/cli_spec.rb
|
192
196
|
- spec/unit/htty/ordered_hash_spec.rb
|