htty 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/History.markdown +46 -0
  2. data/README.markdown +12 -12
  3. data/VERSION +1 -1
  4. data/lib/htty/cli.rb +10 -0
  5. data/lib/htty/cli/command.rb +50 -41
  6. data/lib/htty/cli/commands/http_put.rb +3 -0
  7. data/lib/htty/cli/commands/query_unset.rb +4 -2
  8. data/lib/htty/cli/http_method_command.rb +5 -3
  9. data/spec/integration/htty/cli/commands/query_add_spec.rb +51 -0
  10. data/spec/integration/htty/cli/commands/query_remove_spec.rb +37 -0
  11. data/spec/integration/htty/cli/commands/query_set_spec.rb +72 -0
  12. data/spec/integration/htty/cli/commands/query_unset_spec.rb +37 -0
  13. data/spec/unit/htty/cli/commands/address_spec.rb +103 -0
  14. data/spec/unit/htty/cli/commands/body_clear_spec.rb +64 -0
  15. data/spec/unit/htty/cli/commands/body_request_spec.rb +72 -0
  16. data/spec/unit/htty/cli/commands/body_response_spec.rb +70 -0
  17. data/spec/unit/htty/cli/commands/body_set_spec.rb +71 -0
  18. data/spec/unit/htty/cli/commands/body_unset_spec.rb +69 -0
  19. data/spec/unit/htty/cli/commands/cd_spec.rb +57 -0
  20. data/spec/unit/htty/cli/commands/cookie_add_spec.rb +64 -0
  21. data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +64 -0
  22. data/spec/unit/htty/cli/commands/cookies_add_spec.rb +78 -0
  23. data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +64 -0
  24. data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +73 -0
  25. data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +69 -0
  26. data/spec/unit/htty/cli/commands/cookies_spec.rb +76 -0
  27. data/spec/unit/htty/cli/commands/cookies_use_spec.rb +75 -0
  28. data/spec/unit/htty/cli/commands/delete_spec.rb +64 -0
  29. data/spec/unit/htty/cli/commands/exit_spec.rb +64 -0
  30. data/spec/unit/htty/cli/commands/follow_spec.rb +70 -0
  31. data/spec/unit/htty/cli/commands/form_add_spec.rb +64 -0
  32. data/spec/unit/htty/cli/commands/form_clear_spec.rb +64 -0
  33. data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +66 -0
  34. data/spec/unit/htty/cli/commands/form_remove_spec.rb +57 -0
  35. data/spec/unit/htty/cli/commands/form_spec.rb +57 -0
  36. data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +64 -0
  37. data/spec/unit/htty/cli/commands/fragment_set_spec.rb +73 -0
  38. data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +72 -0
  39. data/spec/unit/htty/cli/commands/get_spec.rb +64 -0
  40. data/spec/unit/htty/cli/commands/header_set_spec.rb +64 -0
  41. data/spec/unit/htty/cli/commands/header_unset_spec.rb +64 -0
  42. data/spec/unit/htty/cli/commands/headers_clear_spec.rb +64 -0
  43. data/spec/unit/htty/cli/commands/headers_request_spec.rb +81 -0
  44. data/spec/unit/htty/cli/commands/headers_response_spec.rb +77 -0
  45. data/spec/unit/htty/cli/commands/headers_set_spec.rb +74 -0
  46. data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +71 -0
  47. data/spec/unit/htty/cli/commands/headers_unset_spec.rb +63 -0
  48. data/spec/unit/htty/cli/commands/help_spec.rb +67 -0
  49. data/spec/unit/htty/cli/commands/history_spec.rb +65 -0
  50. data/spec/unit/htty/cli/commands/history_verbose_spec.rb +72 -0
  51. data/spec/unit/htty/cli/commands/host_set_spec.rb +71 -0
  52. data/spec/unit/htty/cli/commands/http_delete_spec.rb +73 -0
  53. data/spec/unit/htty/cli/commands/http_get_spec.rb +75 -0
  54. data/spec/unit/htty/cli/commands/http_head_spec.rb +69 -0
  55. data/spec/unit/htty/cli/commands/http_options_spec.rb +69 -0
  56. data/spec/unit/htty/cli/commands/http_post_spec.rb +71 -0
  57. data/spec/unit/htty/cli/commands/http_put_spec.rb +69 -0
  58. data/spec/unit/htty/cli/commands/http_trace_spec.rb +69 -0
  59. data/spec/unit/htty/cli/commands/path_set_spec.rb +72 -0
  60. data/spec/unit/htty/cli/commands/port_set_spec.rb +73 -0
  61. data/spec/unit/htty/cli/commands/post_spec.rb +64 -0
  62. data/spec/unit/htty/cli/commands/put_spec.rb +64 -0
  63. data/spec/unit/htty/cli/commands/query_add_spec.rb +67 -36
  64. data/spec/unit/htty/cli/commands/query_clear_spec.rb +64 -0
  65. data/spec/unit/htty/cli/commands/query_remove_spec.rb +69 -24
  66. data/spec/unit/htty/cli/commands/query_set_spec.rb +59 -49
  67. data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +73 -0
  68. data/spec/unit/htty/cli/commands/query_unset_spec.rb +75 -0
  69. data/spec/unit/htty/cli/commands/quit_spec.rb +64 -0
  70. data/spec/unit/htty/cli/commands/reuse_spec.rb +72 -0
  71. data/spec/unit/htty/cli/commands/scheme_set_spec.rb +74 -0
  72. data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +67 -0
  73. data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +60 -0
  74. data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +65 -0
  75. data/spec/unit/htty/cli/commands/status_spec.rb +73 -0
  76. data/spec/unit/htty/cli/commands/undo_spec.rb +57 -0
  77. data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +64 -0
  78. data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +75 -0
  79. data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +72 -0
  80. data/spec/unit/htty/cli_spec.rb +8 -2
  81. data/spec/unit/htty/ordered_hash_spec.rb +14 -24
  82. data/spec/unit/htty/preferences_spec.rb +1 -1
  83. data/spec/unit/htty/request_spec.rb +454 -463
  84. metadata +80 -20
@@ -0,0 +1,64 @@
1
+ require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/post")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_post")
4
+
5
+ describe HTTY::CLI::Commands::Post do
6
+ describe 'class' do
7
+ let :klass do
8
+ subject.class
9
+ end
10
+
11
+ it 'should be an alias_for the expected command' do
12
+ klass.alias_for.should == HTTY::CLI::Commands::HttpPost
13
+ end
14
+
15
+ it 'should have the expected aliases' do
16
+ klass.aliases.should == []
17
+ end
18
+
19
+ it 'should belong to the expected category' do
20
+ klass.category.should == 'Issuing Requests'
21
+ end
22
+
23
+ it 'should have the expected command_line' do
24
+ klass.command_line.should == 'pos[t]'
25
+ end
26
+
27
+ it 'should have the expected command_line_arguments' do
28
+ klass.command_line_arguments.should == nil
29
+ end
30
+
31
+ it 'should have the expected help' do
32
+ klass.help.should == "Alias for \e[1mhttp-po[st]\e[0m"
33
+ end
34
+
35
+ it 'should have the expected help_extended' do
36
+ klass.help_extended.should == "Alias for \e[1mhttp-po[st]\e[0m."
37
+ end
38
+
39
+ it 'should have the expected see_also_commands' do
40
+ klass.see_also_commands.should == [HTTY::CLI::Commands::HttpPost]
41
+ end
42
+
43
+ describe 'build_for' do
44
+ it 'should correctly handle a valid, unabbreviated command line' do
45
+ built = klass.build_for('post', :session => :the_session)
46
+ built.should be_instance_of(klass)
47
+ built.arguments.should == []
48
+ built.session.should == :the_session
49
+ end
50
+
51
+ it 'should correctly handle a valid, abbreviated command line' do
52
+ built = klass.build_for('pos', :session => :a_session)
53
+ built.should be_instance_of(klass)
54
+ built.arguments.should == []
55
+ built.session.should == :a_session
56
+ end
57
+
58
+ it 'should correctly handle a command line with a bad command' do
59
+ built = klass.build_for('x', :session => :another_session)
60
+ built.should == nil
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,64 @@
1
+ require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/put")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_put")
4
+
5
+ describe HTTY::CLI::Commands::Put do
6
+ describe 'class' do
7
+ let :klass do
8
+ subject.class
9
+ end
10
+
11
+ it 'should be an alias_for the expected command' do
12
+ klass.alias_for.should == HTTY::CLI::Commands::HttpPut
13
+ end
14
+
15
+ it 'should have the expected aliases' do
16
+ klass.aliases.should == []
17
+ end
18
+
19
+ it 'should belong to the expected category' do
20
+ klass.category.should == 'Issuing Requests'
21
+ end
22
+
23
+ it 'should have the expected command_line' do
24
+ klass.command_line.should == 'pu[t]'
25
+ end
26
+
27
+ it 'should have the expected command_line_arguments' do
28
+ klass.command_line_arguments.should == nil
29
+ end
30
+
31
+ it 'should have the expected help' do
32
+ klass.help.should == "Alias for \e[1mhttp-pu[t]\e[0m"
33
+ end
34
+
35
+ it 'should have the expected help_extended' do
36
+ klass.help_extended.should == "Alias for \e[1mhttp-pu[t]\e[0m."
37
+ end
38
+
39
+ it 'should have the expected see_also_commands' do
40
+ klass.see_also_commands.should == [HTTY::CLI::Commands::HttpPut]
41
+ end
42
+
43
+ describe 'build_for' do
44
+ it 'should correctly handle a valid, unabbreviated command line' do
45
+ built = klass.build_for('put', :session => :the_session)
46
+ built.should be_instance_of(klass)
47
+ built.arguments.should == []
48
+ built.session.should == :the_session
49
+ end
50
+
51
+ it 'should correctly handle a valid, abbreviated command line' do
52
+ built = klass.build_for('pu', :session => :a_session)
53
+ built.should be_instance_of(klass)
54
+ built.arguments.should == []
55
+ built.session.should == :a_session
56
+ end
57
+
58
+ it 'should correctly handle a command line with a bad command' do
59
+ built = klass.build_for('x', :session => :another_session)
60
+ built.should == nil
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,51 +1,82 @@
1
1
  require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
2
3
  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
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
5
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
6
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset")
7
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset_all")
4
8
 
5
9
  describe HTTY::CLI::Commands::QueryAdd do
6
- before :each do
7
- @session = HTTY::Session.new('')
8
- end
10
+ describe 'class' do
11
+ let :klass do
12
+ subject.class
13
+ end
9
14
 
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
15
+ it 'should be an alias_for the expected command' do
16
+ klass.alias_for.should == nil
16
17
  end
17
18
 
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
19
+ it 'should have the expected aliases' do
20
+ klass.aliases.should == []
24
21
  end
25
- end
26
22
 
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
23
+ it 'should belong to the expected category' do
24
+ klass.category.should == 'Navigation'
33
25
  end
34
26
 
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
27
+ it 'should have the expected command_line' do
28
+ klass.command_line.should == 'query-a[dd]'
41
29
  end
42
- end
43
30
 
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
31
+ it 'should have the expected command_line_arguments' do
32
+ klass.command_line_arguments.should == 'NAME [VALUE [NAME [VALUE ...]]]'
33
+ end
34
+
35
+ it 'should have the expected help' do
36
+ klass.help.should == "Adds query-string parameters to the request's " +
37
+ 'address'
38
+ end
39
+
40
+ it 'should have the expected help_extended' do
41
+ expected = <<-end_help_extended
42
+ Adds one or more query-string parameters used for the request. Does not communicate with the host.
50
43
 
44
+ The difference between this command and \e[1mquery-s[et]\e[0m is that this command adds duplicate parameters instead of replacing any of them.
45
+
46
+ The name(s) and value(s) of the query-string parameter(s) will be URL-encoded if necessary.
47
+
48
+ The console prompt shows the address for the current request.
49
+ end_help_extended
50
+ klass.help_extended.should == expected.chomp
51
+ end
52
+
53
+ it 'should have the expected see_also_commands' do
54
+ klass.see_also_commands.should == [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
+ describe 'build_for' do
62
+ it 'should correctly handle a valid, unabbreviated command line' do
63
+ built = klass.build_for('query-add foo bar', :session => :the_session)
64
+ built.should be_instance_of(klass)
65
+ built.arguments.should == %w(foo bar)
66
+ built.session.should == :the_session
67
+ end
68
+
69
+ it 'should correctly handle a valid, abbreviated command line' do
70
+ built = klass.build_for('query-a baz', :session => :a_session)
71
+ built.should be_instance_of(klass)
72
+ built.arguments.should == ['baz']
73
+ built.session.should == :a_session
74
+ end
75
+
76
+ it 'should correctly handle a command line with a bad command' do
77
+ built = klass.build_for('x qux', :session => :another_session)
78
+ built.should == nil
79
+ end
80
+ end
81
+ end
51
82
  end
@@ -0,0 +1,64 @@
1
+ require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_clear")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset_all")
4
+
5
+ describe HTTY::CLI::Commands::QueryClear do
6
+ describe 'class' do
7
+ let :klass do
8
+ subject.class
9
+ end
10
+
11
+ it 'should be an alias_for the expected command' do
12
+ klass.alias_for.should == HTTY::CLI::Commands::QueryUnsetAll
13
+ end
14
+
15
+ it 'should have the expected aliases' do
16
+ klass.aliases.should == []
17
+ end
18
+
19
+ it 'should belong to the expected category' do
20
+ klass.category.should == 'Navigation'
21
+ end
22
+
23
+ it 'should have the expected command_line' do
24
+ klass.command_line.should == 'query-c[lear]'
25
+ end
26
+
27
+ it 'should have the expected command_line_arguments' do
28
+ klass.command_line_arguments.should == nil
29
+ end
30
+
31
+ it 'should have the expected help' do
32
+ klass.help.should == "Alias for \e[1mquery-unset-[all]\e[0m"
33
+ end
34
+
35
+ it 'should have the expected help_extended' do
36
+ klass.help_extended.should == "Alias for \e[1mquery-unset-[all]\e[0m."
37
+ end
38
+
39
+ it 'should have the expected see_also_commands' do
40
+ klass.see_also_commands.should == [HTTY::CLI::Commands::QueryUnsetAll]
41
+ end
42
+
43
+ describe 'build_for' do
44
+ it 'should correctly handle a valid, unabbreviated command line' do
45
+ built = klass.build_for('query-clear', :session => :the_session)
46
+ built.should be_instance_of(klass)
47
+ built.arguments.should == []
48
+ built.session.should == :the_session
49
+ end
50
+
51
+ it 'should correctly handle a valid, abbreviated command line' do
52
+ built = klass.build_for('query-c', :session => :a_session)
53
+ built.should be_instance_of(klass)
54
+ built.arguments.should == []
55
+ built.session.should == :a_session
56
+ end
57
+
58
+ it 'should correctly handle a command line with a bad command' do
59
+ built = klass.build_for('x', :session => :another_session)
60
+ built.should == nil
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,37 +1,82 @@
1
1
  require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
2
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
5
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
6
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset")
7
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset_all")
4
8
 
5
9
  describe HTTY::CLI::Commands::QueryRemove do
6
- before :each do
7
- @session = HTTY::Session.new('')
8
- end
10
+ describe 'class' do
11
+ let :klass do
12
+ subject.class
13
+ end
9
14
 
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'
15
+ it 'should be an alias_for the expected command' do
16
+ klass.alias_for.should == nil
13
17
  end
14
18
 
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
19
+ it 'should have the expected aliases' do
20
+ klass.aliases.should == []
20
21
  end
21
22
 
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
23
+ it 'should belong to the expected category' do
24
+ klass.category.should == 'Navigation'
27
25
  end
28
- end
29
26
 
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
27
+ it 'should have the expected command_line' do
28
+ klass.command_line.should == 'query-r[emove]'
29
+ end
30
+
31
+ it 'should have the expected command_line_arguments' do
32
+ klass.command_line_arguments.should == 'NAME [VALUE]'
33
+ end
34
+
35
+ it 'should have the expected help' do
36
+ klass.help.should == 'Removes query-string parameters from the end of ' +
37
+ "the request's address"
38
+ end
39
+
40
+ it 'should have the expected help_extended' do
41
+ expected = <<-end_help_extended
42
+ Removes one or more a query-string parameters used for the request. Does not communicate with the host.
43
+
44
+ The difference between this command and \e[1mquery-unset\e[0m is that this command removes matching parameters one at a time from the end of the address instead of removing all matches.
36
45
 
46
+ The name and value of the query-string parameter will be URL-encoded if necessary.
47
+
48
+ The console prompt shows the address for the current request.
49
+ end_help_extended
50
+ klass.help_extended.should == expected.chomp
51
+ end
52
+
53
+ it 'should have the expected see_also_commands' do
54
+ klass.see_also_commands.should == [HTTY::CLI::Commands::QueryAdd,
55
+ HTTY::CLI::Commands::QuerySet,
56
+ HTTY::CLI::Commands::QueryUnset,
57
+ HTTY::CLI::Commands::QueryUnsetAll,
58
+ HTTY::CLI::Commands::Address]
59
+ end
60
+
61
+ describe 'build_for' do
62
+ it 'should correctly handle a valid, unabbreviated command line' do
63
+ built = klass.build_for('query-remove foo bar', :session => :the_session)
64
+ built.should be_instance_of(klass)
65
+ built.arguments.should == %w(foo bar)
66
+ built.session.should == :the_session
67
+ end
68
+
69
+ it 'should correctly handle a valid, abbreviated command line' do
70
+ built = klass.build_for('query-r baz', :session => :a_session)
71
+ built.should be_instance_of(klass)
72
+ built.arguments.should == ['baz']
73
+ built.session.should == :a_session
74
+ end
75
+
76
+ it 'should correctly handle a command line with a bad command' do
77
+ built = klass.build_for('x qux', :session => :another_session)
78
+ built.should == nil
79
+ end
80
+ end
81
+ end
37
82
  end
@@ -1,72 +1,82 @@
1
1
  require 'rspec'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
4
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
2
5
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
3
- require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/session")
6
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset")
7
+ require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset_all")
4
8
 
5
9
  describe HTTY::CLI::Commands::QuerySet do
6
- before :all do
7
- @session = HTTY::Session.new('')
8
- end
10
+ describe 'class' do
11
+ let :klass do
12
+ subject.class
13
+ end
9
14
 
10
- describe 'with one argument' do
11
- it 'should assign a single key' do
12
- query_set = create_query_set_and_perform('test')
13
- query_set.session.requests.last.uri.query.should == 'test'
15
+ it 'should be an alias_for the expected command' do
16
+ klass.alias_for.should == nil
14
17
  end
15
- end
16
18
 
17
- describe 'with two arguments' do
18
- it 'should assign a key-value pair' do
19
- query_set = create_query_set_and_perform('test', 'true')
20
- query_set.session.requests.last.uri.query.should == 'test=true'
19
+ it 'should have the expected aliases' do
20
+ klass.aliases.should == []
21
21
  end
22
- end
23
22
 
24
- describe 'with three arguments' do
25
- it 'should assign a key-value pair and a valueless key' do
26
- query_set = create_query_set_and_perform('test', 'true', 'more')
27
- query_set.session.requests.last.uri.query.should == 'test=true&more'
23
+ it 'should belong to the expected category' do
24
+ klass.category.should == 'Navigation'
28
25
  end
29
- end
30
26
 
31
- describe 'with four arguments' do
32
- it 'should assign two key-value pairs' do
33
- query_set = create_query_set_and_perform('test', 'true', 'more', 'false')
34
- query_set.session.requests.last.uri.query.should == 'test=true&more=false'
27
+ it 'should have the expected command_line' do
28
+ klass.command_line.should == 'query-s[et]'
35
29
  end
36
- end
37
30
 
38
- describe 'with duplicate keys' do
39
- it 'should replace existing key' do
40
- @session.requests.last.uri.query = 'test=true'
41
- query_set = create_query_set_and_perform('test', 'false')
42
- query_set.session.requests.last.uri.query.should == 'test=false'
31
+ it 'should have the expected command_line_arguments' do
32
+ klass.command_line_arguments.should == 'NAME [VALUE [NAME [VALUE ...]]]'
43
33
  end
44
34
 
45
- it 'should maintain field location' do
46
- @session.requests.last.uri.query = 'test=true&more=true'
47
- query_set = create_query_set_and_perform('test', 'false')
48
- query_set.session.requests.last.uri.query.should == 'test=false&more=true'
35
+ it 'should have the expected help' do
36
+ klass.help.should == "Sets query-string parameters in the request's " +
37
+ 'address'
49
38
  end
50
39
 
51
- it 'should replace multiple instances with one' do
52
- @session.requests.last.uri.query = 'test=true&more=true&test=true'
53
- query_set = create_query_set_and_perform('test', 'false')
54
- query_set.session.requests.last.uri.query.should == 'test=false&more=true'
40
+ it 'should have the expected help_extended' do
41
+ expected = <<-end_help_extended
42
+ Sets one or more query-string parameters used for the request. Does not communicate with the host.
43
+
44
+ The difference between this command and \e[1mquery-a[dd]\e[0m is that this command replaces any duplicate parameters instead of adding more.
45
+
46
+ The name(s) and value(s) of the query-string parameter(s) will be URL-encoded if necessary.
47
+
48
+ The console prompt shows the address for the current request.
49
+ end_help_extended
50
+ klass.help_extended.should == expected.chomp
55
51
  end
56
52
 
57
- it 'should play nice with nested fields' do
58
- @session.requests.last.uri.query = 'test[my][]=1'
59
- query_set = create_query_set_and_perform('test[my][]', '2')
60
- query_set = create_query_set_and_perform('test', '3')
61
- query_set.session.requests.last.uri.query.should == 'test[my][]=2&test=3'
53
+ it 'should have the expected see_also_commands' do
54
+ klass.see_also_commands.should == [HTTY::CLI::Commands::QueryUnset,
55
+ HTTY::CLI::Commands::QueryUnsetAll,
56
+ HTTY::CLI::Commands::QueryAdd,
57
+ HTTY::CLI::Commands::QueryRemove,
58
+ HTTY::CLI::Commands::Address]
62
59
  end
63
- end
64
60
 
65
- def create_query_set_and_perform(*arguments)
66
- query_set = HTTY::CLI::Commands::QuerySet.new(:session => @session,
67
- :arguments => arguments)
68
- query_set.perform
69
- query_set
70
- end
61
+ describe 'build_for' do
62
+ it 'should correctly handle a valid, unabbreviated command line' do
63
+ built = klass.build_for('query-set foo bar', :session => :the_session)
64
+ built.should be_instance_of(klass)
65
+ built.arguments.should == %w(foo bar)
66
+ built.session.should == :the_session
67
+ end
71
68
 
69
+ it 'should correctly handle a valid, abbreviated command line' do
70
+ built = klass.build_for('query-s baz', :session => :a_session)
71
+ built.should be_instance_of(klass)
72
+ built.arguments.should == ['baz']
73
+ built.session.should == :a_session
74
+ end
75
+
76
+ it 'should correctly handle a command line with a bad command' do
77
+ built = klass.build_for('x qux', :session => :another_session)
78
+ built.should == nil
79
+ end
80
+ end
81
+ end
72
82
  end