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.
- checksums.yaml +7 -0
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/.travis.yml +21 -3
- data/.yardopts +1 -1
- data/Gemfile +2 -2
- data/Guardfile +12 -10
- data/History.markdown +14 -0
- data/{MIT-LICENSE.markdown → License.markdown} +1 -1
- data/README.markdown +50 -65
- data/Rakefile +2 -2
- data/htty.gemspec +2 -2
- data/lib/htty/cli.rb +59 -74
- data/lib/htty/cli/command.rb +21 -20
- data/lib/htty/cli/commands/body_edit.rb +89 -0
- data/lib/htty/cli/commands/query_add.rb +3 -0
- data/lib/htty/cli/commands/query_set.rb +3 -0
- data/lib/htty/cli/commands/userinfo_set.rb +8 -14
- data/lib/htty/cli/display.rb +14 -12
- data/lib/htty/cli/input_device.rb +75 -0
- data/lib/htty/cli/url_escaping.rb +2 -2
- data/lib/htty/headers.rb +81 -0
- data/lib/htty/no_header_error.rb +10 -0
- data/lib/htty/payload.rb +22 -9
- data/lib/htty/request.rb +67 -43
- data/lib/htty/requests_util.rb +22 -8
- data/lib/htty/response.rb +20 -1
- data/lib/htty/uri.rb +16 -0
- data/lib/htty/version.rb +1 -1
- data/spec/integration/htty/cli/commands/query_add_spec.rb +7 -1
- data/spec/integration/htty/cli/commands/query_remove_spec.rb +19 -1
- data/spec/integration/htty/cli/commands/query_set_spec.rb +9 -3
- data/spec/integration/htty/cli/commands/query_unset_spec.rb +8 -2
- data/spec/spec_helper.rb +69 -0
- data/spec/unit/htty/cli/commands/address_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_edit_spec.rb +18 -0
- data/spec/unit/htty/cli/commands/body_request_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_response_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/body_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cd_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookie_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookie_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_remove_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/cookies_use_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/delete_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/exit_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/follow_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_remove_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/form_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/fragment_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/get_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/header_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/header_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_request_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_response_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_unset_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/headers_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/help_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/history_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/history_verbose_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/host_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_delete_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_get_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_head_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_options_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_patch_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_post_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_put_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/http_trace_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/patch_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/path_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/port_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/post_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/put_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_add_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_remove_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_unset_all_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/query_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/quit_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/reuse_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/scheme_set_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/shared_examples_for_commands.rb +55 -0
- data/spec/unit/htty/cli/commands/ssl_verification_off_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/ssl_verification_on_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/ssl_verification_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/status_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/undo_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/userinfo_clear_spec.rb +1 -1
- data/spec/unit/htty/cli/commands/userinfo_set_spec.rb +23 -1
- data/spec/unit/htty/cli/commands/userinfo_unset_spec.rb +1 -1
- data/spec/unit/htty/cli/display_spec.rb +84 -0
- data/spec/unit/htty/cli_spec.rb +1 -1
- data/spec/unit/htty/command.rb +47 -0
- data/spec/unit/htty/{ordered_hash_spec.rb → headers_spec.rb} +4 -4
- data/spec/unit/htty/payload_spec.rb +60 -0
- data/spec/unit/htty/preferences_spec.rb +1 -1
- data/spec/unit/htty/request_follow_spec.rb +94 -0
- data/spec/unit/htty/request_spec.rb +5 -187
- data/spec/unit/htty/request_userinfo_spec.rb +208 -0
- data/spec/unit/htty/session_spec.rb +1 -1
- data/spec/unit/htty/shared_examples_for_requests.rb +32 -0
- data/spec/unit/htty/url_escaping.rb +70 -0
- data/spec/unit/htty/version_spec.rb +1 -1
- metadata +43 -30
- data/lib/htty/ordered_hash.rb +0 -68
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
data/spec/unit/htty/cli_spec.rb
CHANGED
|
@@ -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 '
|
|
2
|
-
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require File.expand_path("#{File.dirname __FILE__}/../../../lib/htty/headers")
|
|
3
3
|
|
|
4
|
-
describe HTTY::
|
|
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 {
|
|
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
|