htty 1.4.1 → 1.5.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 (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -1
  3. data/.rspec +2 -0
  4. data/.travis.yml +21 -3
  5. data/.yardopts +1 -1
  6. data/Gemfile +2 -2
  7. data/Guardfile +12 -10
  8. data/History.markdown +14 -0
  9. data/{MIT-LICENSE.markdown → License.markdown} +1 -1
  10. data/README.markdown +50 -65
  11. data/Rakefile +2 -2
  12. data/htty.gemspec +2 -2
  13. data/lib/htty/cli.rb +59 -74
  14. data/lib/htty/cli/command.rb +21 -20
  15. data/lib/htty/cli/commands/body_edit.rb +89 -0
  16. data/lib/htty/cli/commands/query_add.rb +3 -0
  17. data/lib/htty/cli/commands/query_set.rb +3 -0
  18. data/lib/htty/cli/commands/userinfo_set.rb +8 -14
  19. data/lib/htty/cli/display.rb +14 -12
  20. data/lib/htty/cli/input_device.rb +75 -0
  21. data/lib/htty/cli/url_escaping.rb +2 -2
  22. data/lib/htty/headers.rb +81 -0
  23. data/lib/htty/no_header_error.rb +10 -0
  24. data/lib/htty/payload.rb +22 -9
  25. data/lib/htty/request.rb +67 -43
  26. data/lib/htty/requests_util.rb +22 -8
  27. data/lib/htty/response.rb +20 -1
  28. data/lib/htty/uri.rb +16 -0
  29. data/lib/htty/version.rb +1 -1
  30. data/spec/integration/htty/cli/commands/query_add_spec.rb +7 -1
  31. data/spec/integration/htty/cli/commands/query_remove_spec.rb +19 -1
  32. data/spec/integration/htty/cli/commands/query_set_spec.rb +9 -3
  33. data/spec/integration/htty/cli/commands/query_unset_spec.rb +8 -2
  34. data/spec/spec_helper.rb +69 -0
  35. data/spec/unit/htty/cli/commands/address_spec.rb +1 -1
  36. data/spec/unit/htty/cli/commands/body_clear_spec.rb +1 -1
  37. data/spec/unit/htty/cli/commands/body_edit_spec.rb +18 -0
  38. data/spec/unit/htty/cli/commands/body_request_spec.rb +1 -1
  39. data/spec/unit/htty/cli/commands/body_response_spec.rb +1 -1
  40. data/spec/unit/htty/cli/commands/body_set_spec.rb +1 -1
  41. data/spec/unit/htty/cli/commands/body_unset_spec.rb +1 -1
  42. data/spec/unit/htty/cli/commands/cd_spec.rb +1 -1
  43. data/spec/unit/htty/cli/commands/cookie_add_spec.rb +1 -1
  44. data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +1 -1
  45. data/spec/unit/htty/cli/commands/cookies_add_spec.rb +1 -1
  46. data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +1 -1
  47. data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +1 -1
  48. data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +1 -1
  49. data/spec/unit/htty/cli/commands/cookies_spec.rb +1 -1
  50. data/spec/unit/htty/cli/commands/cookies_use_spec.rb +1 -1
  51. data/spec/unit/htty/cli/commands/delete_spec.rb +1 -1
  52. data/spec/unit/htty/cli/commands/exit_spec.rb +1 -1
  53. data/spec/unit/htty/cli/commands/follow_spec.rb +1 -1
  54. data/spec/unit/htty/cli/commands/form_add_spec.rb +1 -1
  55. data/spec/unit/htty/cli/commands/form_clear_spec.rb +1 -1
  56. data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +1 -1
  57. data/spec/unit/htty/cli/commands/form_remove_spec.rb +1 -1
  58. data/spec/unit/htty/cli/commands/form_spec.rb +1 -1
  59. data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +1 -1
  60. data/spec/unit/htty/cli/commands/fragment_set_spec.rb +1 -1
  61. data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +1 -1
  62. data/spec/unit/htty/cli/commands/get_spec.rb +1 -1
  63. data/spec/unit/htty/cli/commands/header_set_spec.rb +1 -1
  64. data/spec/unit/htty/cli/commands/header_unset_spec.rb +1 -1
  65. data/spec/unit/htty/cli/commands/headers_clear_spec.rb +1 -1
  66. data/spec/unit/htty/cli/commands/headers_request_spec.rb +1 -1
  67. data/spec/unit/htty/cli/commands/headers_response_spec.rb +1 -1
  68. data/spec/unit/htty/cli/commands/headers_set_spec.rb +1 -1
  69. data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +1 -1
  70. data/spec/unit/htty/cli/commands/headers_unset_spec.rb +1 -1
  71. data/spec/unit/htty/cli/commands/help_spec.rb +1 -1
  72. data/spec/unit/htty/cli/commands/history_spec.rb +1 -1
  73. data/spec/unit/htty/cli/commands/history_verbose_spec.rb +1 -1
  74. data/spec/unit/htty/cli/commands/host_set_spec.rb +1 -1
  75. data/spec/unit/htty/cli/commands/http_delete_spec.rb +1 -1
  76. data/spec/unit/htty/cli/commands/http_get_spec.rb +1 -1
  77. data/spec/unit/htty/cli/commands/http_head_spec.rb +1 -1
  78. data/spec/unit/htty/cli/commands/http_options_spec.rb +1 -1
  79. data/spec/unit/htty/cli/commands/http_patch_spec.rb +1 -1
  80. data/spec/unit/htty/cli/commands/http_post_spec.rb +1 -1
  81. data/spec/unit/htty/cli/commands/http_put_spec.rb +1 -1
  82. data/spec/unit/htty/cli/commands/http_trace_spec.rb +1 -1
  83. data/spec/unit/htty/cli/commands/patch_spec.rb +1 -1
  84. data/spec/unit/htty/cli/commands/path_set_spec.rb +1 -1
  85. data/spec/unit/htty/cli/commands/port_set_spec.rb +1 -1
  86. data/spec/unit/htty/cli/commands/post_spec.rb +1 -1
  87. data/spec/unit/htty/cli/commands/put_spec.rb +1 -1
  88. data/spec/unit/htty/cli/commands/query_add_spec.rb +1 -1
  89. data/spec/unit/htty/cli/commands/query_clear_spec.rb +1 -1
  90. data/spec/unit/htty/cli/commands/query_remove_spec.rb +1 -1
  91. data/spec/unit/htty/cli/commands/query_set_spec.rb +1 -1
  92. data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +1 -1
  93. data/spec/unit/htty/cli/commands/query_unset_spec.rb +1 -1
  94. data/spec/unit/htty/cli/commands/quit_spec.rb +1 -1
  95. data/spec/unit/htty/cli/commands/reuse_spec.rb +1 -1
  96. data/spec/unit/htty/cli/commands/scheme_set_spec.rb +1 -1
  97. data/spec/unit/htty/cli/commands/shared_examples_for_commands.rb +55 -0
  98. data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +1 -1
  99. data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +1 -1
  100. data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +1 -1
  101. data/spec/unit/htty/cli/commands/status_spec.rb +1 -1
  102. data/spec/unit/htty/cli/commands/undo_spec.rb +1 -1
  103. data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +1 -1
  104. data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +23 -1
  105. data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +1 -1
  106. data/spec/unit/htty/cli/display_spec.rb +84 -0
  107. data/spec/unit/htty/cli_spec.rb +1 -1
  108. data/spec/unit/htty/command.rb +47 -0
  109. data/spec/unit/htty/{ordered_hash_spec.rb → headers_spec.rb} +4 -4
  110. data/spec/unit/htty/payload_spec.rb +60 -0
  111. data/spec/unit/htty/preferences_spec.rb +1 -1
  112. data/spec/unit/htty/request_follow_spec.rb +94 -0
  113. data/spec/unit/htty/request_spec.rb +5 -187
  114. data/spec/unit/htty/request_userinfo_spec.rb +208 -0
  115. data/spec/unit/htty/session_spec.rb +1 -1
  116. data/spec/unit/htty/shared_examples_for_requests.rb +32 -0
  117. data/spec/unit/htty/url_escaping.rb +70 -0
  118. data/spec/unit/htty/version_spec.rb +1 -1
  119. metadata +43 -30
  120. data/lib/htty/ordered_hash.rb +0 -68
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_get")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_options")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/follow")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_delete")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_get")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/follow")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_delete")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_get")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_delete")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_get")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_patch")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_get")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_trace")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/patch")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_patch")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/cd")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/path_set")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/port_set")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/scheme_set")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/post")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_post")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/put")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/http_put")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_clear")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_unset_all")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_clear")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_set")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_add")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/query_remove")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/exit")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/quit")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/history")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/history_verbose")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/reuse")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/port_set")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/scheme_set")
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a command' do
4
+ it 'should be an alias_for the expected command' do
5
+ described_class.alias_for.should == alias_for
6
+ end
7
+
8
+ it 'should have the expected aliases' do
9
+ described_class.aliases.should == aliases
10
+ end
11
+
12
+ it 'should belong to the expected category' do
13
+ described_class.category.should == category
14
+ end
15
+
16
+ it 'should have the expected command_line' do
17
+ described_class.command_line.should == command_line
18
+ end
19
+
20
+ it 'should have the expected command_line_arguments' do
21
+ described_class.command_line_arguments.should == arguments
22
+ end
23
+
24
+ it 'should have the expected help' do
25
+ described_class.help.should_not be_empty
26
+ end
27
+
28
+ it 'should have the expected help_extended' do
29
+ described_class.help_extended.should be_multiline
30
+ end
31
+
32
+ it 'should have the expected see_also_commands' do
33
+ described_class.see_also_commands.should =~ see_also_commands
34
+ end
35
+
36
+ describe 'build_for' do
37
+ it 'should correctly handle a valid, unabbreviated command line' do
38
+ command_used = command_line.tr('[]', '')
39
+ built = described_class.build_for(command_used, :session => :the_session)
40
+ built.should be_instance_of(described_class)
41
+ built.arguments.should == []
42
+ built.session.should == :the_session
43
+ end
44
+
45
+ it 'should correctly handle a valid, abbreviated command line' do
46
+ if command_line.match /^(.*)\[(.*?)\]$/
47
+ command_used = $1 + $2[0, rand($2.length)+1]
48
+ built = described_class.build_for(command_used, :session => :the_session)
49
+ built.should be_instance_of(described_class)
50
+ built.arguments.should == []
51
+ built.session.should == :the_session
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_off")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_on")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_off")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_on")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_off")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/ssl_verification_on")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/body_response")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/headers_response")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/status")
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/undo")
3
3
 
4
4
  describe HTTY::CLI::Commands::Undo do
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_clear")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_unset")
4
4
 
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_set")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_unset")
@@ -71,5 +71,27 @@ The console prompt shows the address for the current request. Userinfo appears i
71
71
  built.should == nil
72
72
  end
73
73
  end
74
+
75
+ describe '#sanitize_arguments' do
76
+ context 'when only one argument like username:password' do
77
+ let(:arguments) {['username:password']}
78
+
79
+ it 'should be splitted in two arguments' do
80
+ klass.sanitize_arguments(arguments).should == [
81
+ 'username', 'password'
82
+ ]
83
+ end
84
+ end
85
+
86
+ context 'when arguments contains special characters' do
87
+ let(:arguments) {['user/name', 'password']}
88
+
89
+ it 'should escape them' do
90
+ klass.sanitize_arguments(arguments).should == [
91
+ 'user%2Fname', 'password'
92
+ ]
93
+ end
94
+ end
95
+ end
74
96
  end
75
97
  end
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/address")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_clear")
4
4
  require File.expand_path("#{File.dirname __FILE__}/../../../../../lib/htty/cli/commands/userinfo_set")
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../../lib/htty/headers")
3
+ require File.expand_path("#{File.dirname __FILE__}/../../../../lib/htty/cli/display")
4
+
5
+ describe HTTY::CLI::Display do
6
+ let(:display) {Class.new.new.extend(HTTY::CLI::Display)}
7
+
8
+ describe '#show_headers' do
9
+ it 'displays headers keeping the text case' do
10
+ headers = HTTY::Headers.new('user-agent' => 'htty/1.4.1').to_a
11
+
12
+ expect {display.show_headers(headers)}.to print_on_stdout(
13
+ "user-agent:#{display.strong('')} htty/1.4.1\n"
14
+ )
15
+ end
16
+
17
+ context 'with one header' do
18
+ let(:headers) {HTTY::Headers.new('User-Agent' => 'htty/1.4.1').to_a}
19
+
20
+ it 'displays the header starting from the beginning of the line' do
21
+ expect {display.show_headers(headers)}.to print_on_stdout(
22
+ "User-Agent:#{display.strong('')} htty/1.4.1\n"
23
+ )
24
+ end
25
+ end
26
+
27
+ context 'with few headers' do
28
+ let(:headers) {
29
+ headers = HTTY::Headers.new
30
+ headers['User-Agent'] = 'htty/1.4.1'
31
+ headers['Content-Type'] = 'application/json'
32
+ headers.to_a
33
+ }
34
+
35
+ it 'aligns headers on colons' do
36
+ expect {display.show_headers(headers)}.to print_on_stdout(
37
+ " User-Agent:#{display.strong('')} htty/1.4.1\n" +
38
+ "Content-Type:#{display.strong('')} application/json\n"
39
+ )
40
+ end
41
+ end
42
+
43
+ context 'with marked headers' do
44
+ context 'with one header' do
45
+ let(:headers) {HTTY::Headers.new('User-Agent' => 'htty/1.4.1').to_a}
46
+ let(:options) {{:show_mercantile_next_to => 'User-Agent'}}
47
+
48
+ it 'displays the header starting from the beginning of the line' do
49
+ expect {display.show_headers(headers, options)}.to print_on_stdout(
50
+ "User-Agent:#{display.strong('@')} htty/1.4.1\n"
51
+ )
52
+ end
53
+ end
54
+
55
+ context 'with few headers' do
56
+ let(:options) {{:show_mercantile_next_to => 'Content-Type'}}
57
+ let(:headers) {
58
+ headers = HTTY::Headers.new
59
+ headers['User-Agent'] = 'htty/1.4.1'
60
+ headers['Content-Type'] = 'application/json'
61
+ headers.to_a
62
+ }
63
+
64
+ it 'aligns colons and mercantiles' do
65
+ expect {display.show_headers(headers, options)}.to print_on_stdout(
66
+ " User-Agent:#{display.strong('')} htty/1.4.1\n" +
67
+ "Content-Type:#{display.strong('@')} application/json\n"
68
+ )
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'when asked to mark an header' do
74
+ let(:options) {{:show_mercantile_next_to => 'Content-Type'}}
75
+ let(:headers) {HTTY::Headers.new('content-type' => 'application/json').to_a}
76
+
77
+ it 'marks headers indipendently of the text case' do
78
+ expect {display.show_headers(headers, options)}.to print_on_stdout(
79
+ "content-type:#{display.strong('@')} application/json\n"
80
+ )
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,4 +1,4 @@
1
- require 'rspec'
1
+ require 'spec_helper'
2
2
  require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/cli")
3
3
  require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/request")
4
4
 
@@ -0,0 +1,47 @@
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,7 +1,7 @@
1
- require 'rspec'
2
- require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/ordered_hash")
1
+ require 'spec_helper'
2
+ require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/headers")
3
3
 
4
- describe HTTY::OrderedHash do
4
+ describe HTTY::Headers do
5
5
  describe 'that is empty' do
6
6
  it { should be_empty }
7
7
 
@@ -20,7 +20,7 @@ describe HTTY::OrderedHash do
20
20
  end
21
21
 
22
22
  describe 'that has values out of order' do
23
- subject { HTTY::OrderedHash.new('foo' => 'bar', 'baz' => 'qux') }
23
+ subject { described_class.new('foo' => 'bar', 'baz' => 'qux') }
24
24
 
25
25
  it { should == {'foo' => 'bar', 'baz' => 'qux'} }
26
26
 
@@ -0,0 +1,60 @@
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