aitch 1.2.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac6be3c16c842bbd1555aed0de859b6e62bf59f511cce28a6c441efd980e5751
4
- data.tar.gz: 2ebc4b41d63c9dd41756bb7fff03b52a6cbca2f56ed310183bc158a822bbdbd9
3
+ metadata.gz: ac06612095a2a08635037c6113a7cb93ce1e22463192ba8f1381e1c7b5657f85
4
+ data.tar.gz: 50b0cfb79bc02cf46ff4f4fd4b762fd06bb44d577c6c6afd9640f1a0141f3dfd
5
5
  SHA512:
6
- metadata.gz: 602da6e2d0aaf3812e7f19b84b48b47eaeac59086345bceb76c601eba64f369ae0833c32980f66b0c026338bb098ad72563d1a4d2fdf8384fe50792856d281a1
7
- data.tar.gz: b35ef25d1e59cd76923e626fdd6d60a735977a35d6560a32fe3313a8421eeccbce9524163775651da6fc017fcd47f7ef20c7ec8a40460d4a627e2d75d334fae8
6
+ metadata.gz: cfc6752814d6b44d4cf455a8cbb269cf8aaabcf3afa6379e34e7fae3a2bc53f2a3218ec33537a05bc8c5cf50c442f95cb126b0f011452caa811f9c2e74c4df5d
7
+ data.tar.gz: b2b1bee33eca007e77e36d687476eb8b3c34f6fa0d5d9d434feabeddef13a42a23bddabe2122000a47d5514b3b16581195cbd9f8fc5d4330dfe6b771c38346c1
@@ -15,12 +15,12 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby: ["2.7.x", "2.6.x", "2.5.x", "3.0.x", "3.1.x"]
18
+ ruby: ["3.0", "3.1", "3.2"]
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v1
21
+ - uses: actions/checkout@v4
22
22
 
23
- - uses: actions/cache@v2
23
+ - uses: actions/cache@v3
24
24
  with:
25
25
  path: vendor/bundle
26
26
  key: >
@@ -31,7 +31,7 @@ jobs:
31
31
  hashFiles('aitch.gemspec') }}
32
32
 
33
33
  - name: Set up Ruby
34
- uses: actions/setup-ruby@v1
34
+ uses: ruby/setup-ruby@v1
35
35
  with:
36
36
  ruby-version: ${{ matrix.ruby }}
37
37
 
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.5
6
+ TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
 
9
9
  Layout/LineLength:
@@ -16,3 +16,9 @@ Naming/AccessorMethodName:
16
16
 
17
17
  Style/DocumentDynamicEvalDefinition:
18
18
  Enabled: false
19
+
20
+ Gemspec/DevelopmentDependencies:
21
+ Enabled: false
22
+
23
+ Minitest/MultipleAssertions:
24
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ - **2.0.0**
4
+ - Fix error when content type is not available on response.
5
+ - Stop supporting old ruby versions (require 3.0+).
6
+ - **1.2.2**
7
+ - Transform header key before assigning values.
3
8
  - **1.2.1**
4
9
  - Avoid calling `to_h` when params are array-like.
5
10
  - **1.2.0**
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Aitch
2
2
 
3
- [![Tests](https://github.com/fnando/aitch/workflows/Tests/badge.svg)](https://github.com/fnando/aitch)
3
+ [![Tests](https://github.com/fnando/aitch/actions/workflows/tests.yml/badge.svg)](https://github.com/fnando/aitch/actions/workflows/tests.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/fnando/aitch/badges/gpa.svg)](https://codeclimate.com/github/fnando/aitch)
5
5
  [![Gem Version](https://img.shields.io/gem/v/aitch.svg)](https://rubygems.org/gems/aitch)
6
6
  [![Gem Downloads](https://img.shields.io/gem/dt/aitch.svg)](https://rubygems.org/gems/aitch)
data/aitch.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = spec.description
12
12
  spec.homepage = "http://rubygems.org/gems/aitch"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
15
  spec.metadata["rubygems_mfa_required"] = "true"
16
16
 
17
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
@@ -70,11 +70,11 @@ class Hash
70
70
  #
71
71
  # This method is also aliased as +to_param+.
72
72
  def to_query(namespace = nil)
73
- collect do |key, value|
73
+ filter_map do |key, value|
74
74
  unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
75
75
  value.to_query(namespace ? "#{namespace}[#{key}]" : key)
76
76
  end
77
- end.compact.sort! * "&"
77
+ end.sort! * "&"
78
78
  end
79
79
 
80
80
  alias to_param to_query
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Aitch
4
4
  class Location
5
+ MATCHER = %r{\A/}
6
+
5
7
  attr_reader :redirect_stack, :current_url
6
8
 
7
9
  def initialize(redirect_stack, current_url)
@@ -10,7 +12,7 @@ module Aitch
10
12
  end
11
13
 
12
14
  def location
13
- return current_url unless current_url.match?(%r{\A/}) # rubocop:disable Performance/StartWith
15
+ return current_url unless current_url.match?(MATCHER)
14
16
 
15
17
  uri = find_uri_with_host
16
18
  url = ["#{uri.scheme}://#{uri.hostname}"]
data/lib/aitch/request.rb CHANGED
@@ -4,6 +4,14 @@ module Aitch
4
4
  class Request
5
5
  attr_accessor :request_method, :url, :data, :headers, :options, :redirects
6
6
 
7
+ CONTENT_TYPE = "Content-Type"
8
+ USER_AGENT = "User-Agent"
9
+ ACCEPT_ENCODING = "Accept-Encoding"
10
+ GZIP_DEFLATE = "gzip,deflate"
11
+ HTTPS = "https"
12
+ HEADER_SEPARATOR_RE = /[-_]/
13
+ JSON_RE = /\bjson\b/
14
+
7
15
  alias params= data=
8
16
  alias body= data=
9
17
 
@@ -30,12 +38,12 @@ module Aitch
30
38
  end
31
39
 
32
40
  def content_type=(content_type)
33
- headers["Content-Type"] = content_type
41
+ headers[CONTENT_TYPE] = content_type
34
42
  end
35
43
 
36
44
  def content_type
37
- headers["Content-Type"] ||
38
- options.fetch(:default_headers, {})["Content-Type"]
45
+ headers[CONTENT_TYPE] ||
46
+ options.fetch(:default_headers, {})[CONTENT_TYPE]
39
47
  end
40
48
 
41
49
  def request
@@ -79,7 +87,7 @@ module Aitch
79
87
  body_data = data
80
88
  body_data = data.to_h if data.respond_to?(:to_h) && !data.is_a?(Array)
81
89
 
82
- if content_type.to_s.match?(/\bjson\b/)
90
+ if content_type.to_s.match?(JSON_RE)
83
91
  body_data = ResponseParser::JSONParser.engine.dump(body_data)
84
92
  end
85
93
 
@@ -94,8 +102,9 @@ module Aitch
94
102
  all_headers = options.fetch(:default_headers, {}).merge(headers)
95
103
 
96
104
  all_headers.each do |name, value|
97
- value = value.respond_to?(:call) ? value.call : value
98
- request[name.to_s] = value.to_s
105
+ value = value.call if value.respond_to?(:call)
106
+ name = name.to_s.split(HEADER_SEPARATOR_RE).map(&:capitalize).join("-")
107
+ request[name] = value.to_s
99
108
  end
100
109
  end
101
110
 
@@ -106,7 +115,7 @@ module Aitch
106
115
  end
107
116
 
108
117
  private def set_https(client)
109
- client.use_ssl = uri.scheme == "https"
118
+ client.use_ssl = uri.scheme == HTTPS
110
119
  client.verify_mode = OpenSSL::SSL::VERIFY_PEER
111
120
  end
112
121
 
@@ -120,11 +129,11 @@ module Aitch
120
129
  end
121
130
 
122
131
  private def set_user_agent(request)
123
- request["User-Agent"] = options[:user_agent]
132
+ request[USER_AGENT] = options[:user_agent]
124
133
  end
125
134
 
126
135
  private def set_gzip(request)
127
- request["Accept-Encoding"] = "gzip,deflate"
136
+ request[ACCEPT_ENCODING] = GZIP_DEFLATE
128
137
  end
129
138
 
130
139
  def timeout_exception
@@ -2,25 +2,32 @@
2
2
 
3
3
  module Aitch
4
4
  class Response
5
- extend Forwardable
5
+ JSON_STR = "json"
6
+ XML_STR = "xml"
7
+ HTML_STR = "html"
8
+ EMPTY_STR = ""
9
+ DOUBLE_COLON = "::"
10
+ SPACE_STR = " "
11
+ ERROR_SUFFIX = "_error"
12
+ X_RE = /^x-/
6
13
 
7
- def_delegators :@http_response, :content_type
8
- attr_accessor :redirected_from, :url
14
+ attr_accessor :redirected_from, :url, :content_type
9
15
 
10
16
  def self.description_for_code(code)
11
- [code, DESCRIPTION[code]].compact.join(" ")
17
+ [code, DESCRIPTION[code]].compact.join(SPACE_STR)
12
18
  end
13
19
 
14
20
  def initialize(options, http_response)
15
21
  @options = options
16
22
  @http_response = http_response
17
23
  @redirected_from = options.fetch(:redirected_from, [])
24
+ @content_type = http_response.content_type.to_s
18
25
  end
19
26
 
20
27
  ERRORS.each do |status_code, exception|
21
28
  method_name = Utils
22
- .underscore(exception.name.split("::").last)
23
- .gsub("_error", "")
29
+ .underscore(exception.name.split(DOUBLE_COLON).last)
30
+ .gsub(ERROR_SUFFIX, EMPTY_STR)
24
31
 
25
32
  define_method "#{method_name}?" do
26
33
  code == status_code
@@ -53,15 +60,15 @@ module Aitch
53
60
  end
54
61
 
55
62
  def json?
56
- content_type.include?("json")
63
+ content_type.include?(JSON_STR)
57
64
  end
58
65
 
59
66
  def xml?
60
- content_type.include?("xml")
67
+ content_type.include?(XML_STR)
61
68
  end
62
69
 
63
70
  def html?
64
- content_type.include?("html")
71
+ content_type.include?(HTML_STR)
65
72
  end
66
73
 
67
74
  def data
@@ -71,7 +78,7 @@ module Aitch
71
78
  def headers
72
79
  @headers ||= {}.tap do |headers|
73
80
  @http_response.each_header do |name, value|
74
- headers[name.gsub(/^x-/, "")] = value
81
+ headers[name.gsub(X_RE, EMPTY_STR)] = value
75
82
  end
76
83
  end
77
84
  end
data/lib/aitch/utils.rb CHANGED
@@ -3,8 +3,11 @@
3
3
  module Aitch
4
4
  module Utils
5
5
  extend self
6
+
7
+ MATCHER = /(?<=.)(URI|[A-Z])/
8
+
6
9
  def underscore(string)
7
- string = string.gsub(/(?<=.)(URI|[A-Z])/) do |char|
10
+ string = string.gsub(MATCHER) do |char|
8
11
  "_#{char}"
9
12
  end
10
13
 
data/lib/aitch/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aitch
4
- VERSION = "1.2.1"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -4,25 +4,25 @@ require "test_helper"
4
4
 
5
5
  class AitchTest < Minitest::Test
6
6
  test "defines public API" do
7
- assert Aitch.respond_to?(:get)
8
- assert Aitch.respond_to?(:get!)
9
- assert Aitch.respond_to?(:post)
10
- assert Aitch.respond_to?(:post!)
11
- assert Aitch.respond_to?(:put)
12
- assert Aitch.respond_to?(:put!)
13
- assert Aitch.respond_to?(:patch)
14
- assert Aitch.respond_to?(:patch!)
15
- assert Aitch.respond_to?(:delete)
16
- assert Aitch.respond_to?(:delete!)
17
- assert Aitch.respond_to?(:head)
18
- assert Aitch.respond_to?(:head!)
19
- assert Aitch.respond_to?(:options)
20
- assert Aitch.respond_to?(:options!)
21
- assert Aitch.respond_to?(:trace)
22
- assert Aitch.respond_to?(:trace!)
23
- assert Aitch.respond_to?(:execute)
24
- assert Aitch.respond_to?(:execute!)
25
- assert Aitch.respond_to?(:config)
26
- assert Aitch.respond_to?(:configuration)
7
+ assert_respond_to Aitch, :get
8
+ assert_respond_to Aitch, :get!
9
+ assert_respond_to Aitch, :post
10
+ assert_respond_to Aitch, :post!
11
+ assert_respond_to Aitch, :put
12
+ assert_respond_to Aitch, :put!
13
+ assert_respond_to Aitch, :patch
14
+ assert_respond_to Aitch, :patch!
15
+ assert_respond_to Aitch, :delete
16
+ assert_respond_to Aitch, :delete!
17
+ assert_respond_to Aitch, :head
18
+ assert_respond_to Aitch, :head!
19
+ assert_respond_to Aitch, :options
20
+ assert_respond_to Aitch, :options!
21
+ assert_respond_to Aitch, :trace
22
+ assert_respond_to Aitch, :trace!
23
+ assert_respond_to Aitch, :execute
24
+ assert_respond_to Aitch, :execute!
25
+ assert_respond_to Aitch, :config
26
+ assert_respond_to Aitch, :configuration
27
27
  end
28
28
  end
@@ -9,6 +9,7 @@ class ConfigurationTest < Minitest::Test
9
9
 
10
10
  test "sets default user agent" do
11
11
  user_agent = "Aitch/#{Aitch::VERSION} (http://rubygems.org/gems/aitch)"
12
+
12
13
  assert_equal user_agent, Aitch::Configuration.new.user_agent
13
14
  end
14
15
 
@@ -17,7 +18,7 @@ class ConfigurationTest < Minitest::Test
17
18
  end
18
19
 
19
20
  test "sets default headers" do
20
- assert_equal({}, Aitch::Configuration.new.default_headers)
21
+ assert_empty(Aitch::Configuration.new.default_headers)
21
22
  end
22
23
 
23
24
  test "configures aitch" do
@@ -7,31 +7,37 @@ class DslTest < Minitest::Test
7
7
 
8
8
  test "sets url" do
9
9
  dsl.url "URL"
10
+
10
11
  assert_equal "URL", dsl.url
11
12
  end
12
13
 
13
14
  test "sets options" do
14
15
  dsl.options "OPTIONS"
16
+
15
17
  assert_equal "OPTIONS", dsl.options
16
18
  end
17
19
 
18
20
  test "sets headers" do
19
21
  dsl.headers "HEADERS"
22
+
20
23
  assert_equal "HEADERS", dsl.headers
21
24
  end
22
25
 
23
26
  test "sets data" do
24
27
  dsl.data "DATA"
28
+
25
29
  assert_equal "DATA", dsl.data
26
30
  end
27
31
 
28
32
  test "sets data through params" do
29
33
  dsl.params "PARAMS"
34
+
30
35
  assert_equal "PARAMS", dsl.data
31
36
  end
32
37
 
33
38
  test "sets data through body" do
34
39
  dsl.body "BODY"
40
+
35
41
  assert_equal "BODY", dsl.data
36
42
  end
37
43
 
@@ -41,6 +41,6 @@ class ExecuteBangTest < Minitest::Test
41
41
  response = stub(error?: true, error: "ERROR")
42
42
  Aitch::Request.any_instance.stubs(:perform).returns(response)
43
43
 
44
- assert_raises("ERROR") { Aitch.get!("URL") }
44
+ assert_raises(StandardError, "ERROR") { Aitch.get!("URL") }
45
45
  end
46
46
  end
@@ -7,7 +7,7 @@ class ClientHttpsTest < Minitest::Test
7
7
  let(:client) { request.client }
8
8
 
9
9
  test "sets https" do
10
- assert client.use_ssl?
10
+ assert_predicate client, :use_ssl?
11
11
  end
12
12
 
13
13
  test "sets verification mode" do
@@ -16,6 +16,7 @@ class ClientHttpsTest < Minitest::Test
16
16
 
17
17
  test "sets timeout" do
18
18
  request.options[:timeout] = 20
19
+
19
20
  assert_equal 20, client.read_timeout
20
21
  end
21
22
  end
@@ -14,7 +14,7 @@ class FollowRedirectTest < Minitest::Test
14
14
 
15
15
  response = Aitch.get("http://example.org/")
16
16
 
17
- refute response.redirect?
17
+ refute_predicate response, :redirect?
18
18
  assert_equal "Hello", response.body
19
19
  assert_equal ["http://example.org/", "http://example.com/"], response.redirected_from
20
20
  assert_equal "http://www.example.com/", response.url
@@ -23,6 +23,7 @@ class RequestClassTest < Minitest::Test
23
23
  ].each do |method|
24
24
  test "instantiates #{method.upcase} method" do
25
25
  request = build_request(request_method: method).request
26
+
26
27
  assert_equal "Net::HTTP::#{method.capitalize}", request.class.name
27
28
  end
28
29
  end
@@ -5,6 +5,7 @@ require "test_helper"
5
5
  class RequestTest < Minitest::Test
6
6
  test "sets content type" do
7
7
  request = build_request(content_type: "application/json")
8
+
8
9
  assert_equal "application/json", request.content_type
9
10
  end
10
11
 
@@ -35,26 +36,31 @@ class RequestTest < Minitest::Test
35
36
 
36
37
  test "requests gzip encoding" do
37
38
  request = build_request.request
39
+
38
40
  assert_equal "gzip,deflate", request["Accept-Encoding"]
39
41
  end
40
42
 
41
43
  test "sets path" do
42
44
  request = build_request(url: "http://example.org/some/path").request
45
+
43
46
  assert_equal "/some/path", request.path
44
47
  end
45
48
 
46
49
  test "sets request body from hash" do
47
50
  request = build_request(request_method: "post", data: {a: 1}).request
51
+
48
52
  assert_equal "a=1", request.body
49
53
  end
50
54
 
51
55
  test "sets request body from string" do
52
56
  request = build_request(request_method: "post", data: "some body").request
57
+
53
58
  assert_equal "some body", request.body
54
59
  end
55
60
 
56
61
  test "sets request body from params key" do
57
62
  request = build_request(request_method: "post", params: "some body").request
63
+
58
64
  assert_equal "some body", request.body
59
65
  end
60
66
 
@@ -67,6 +73,7 @@ class RequestTest < Minitest::Test
67
73
  ).request
68
74
 
69
75
  expected = {a: 1}.to_json
76
+
70
77
  assert_equal expected, request.body
71
78
  end
72
79
 
@@ -78,12 +85,14 @@ class RequestTest < Minitest::Test
78
85
  ).request
79
86
 
80
87
  expected = {a: 1}.to_json
88
+
81
89
  assert_equal expected, request.body
82
90
  end
83
91
 
84
92
  test "sets request body from to_h protocol" do
85
93
  data = stub(to_h: {a: 1})
86
94
  request = build_request(request_method: "post", data: data).request
95
+
87
96
  assert_equal "a=1", request.body
88
97
  end
89
98
 
@@ -123,17 +132,25 @@ class RequestTest < Minitest::Test
123
132
 
124
133
  test "sets custom headers" do
125
134
  request = build_request(headers: {"HEADER" => "VALUE"}).request
135
+
126
136
  assert_equal "VALUE", request["HEADER"]
127
137
  end
128
138
 
139
+ test "sets headers from underscored headers" do
140
+ request = build_request(headers: {content_type: "text/plain"}).request
141
+
142
+ assert_equal "text/plain", request["Content-Type"]
143
+ end
144
+
129
145
  test "executes headers with callable protocol" do
130
146
  request = build_request(headers: {"HEADER" => -> { "VALUE" }}).request
147
+
131
148
  assert_equal "VALUE", request["HEADER"]
132
149
  end
133
150
 
134
151
  test "sets basic auth credentials" do
135
152
  request = build_request(options: {user: "USER", password: "PASS"}).request
136
- credentials = Base64.decode64(request["Authorization"].gsub(/Basic /, ""))
153
+ credentials = Base64.decode64(request["Authorization"].gsub("Basic ", ""))
137
154
 
138
155
  assert_equal "USER:PASS", credentials
139
156
  end
@@ -8,7 +8,7 @@ class ErrorsTest < Minitest::Test
8
8
 
9
9
  test "detects response as #{name}" do
10
10
  config = {}
11
- http_response = stub(code: code)
11
+ http_response = stub(code: code, content_type: "text/html")
12
12
  response = Aitch::Response.new(config, http_response)
13
13
 
14
14
  assert response.public_send("#{name}?")
@@ -7,7 +7,7 @@ class HtmlResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "", content_type: "text/html")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.html?
10
+ assert_predicate response, :html?
11
11
  end
12
12
 
13
13
  test "returns html" do
@@ -7,7 +7,7 @@ class JsonResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "[]", content_type: "application/json")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.json?
10
+ assert_predicate response, :json?
11
11
  end
12
12
 
13
13
  test "returns json" do
@@ -6,16 +6,26 @@ class Status3xxTest < Minitest::Test
6
6
  setup { Aitch.configuration.follow_redirect = false }
7
7
 
8
8
  test "sets default redirected from" do
9
- assert_equal [], Aitch::Response.new({}, stub("response")).redirected_from
9
+ response =
10
+ Aitch::Response.new({}, stub("response", content_type: "text/html"))
11
+
12
+ assert_empty response.redirected_from
10
13
  end
11
14
 
12
15
  test "uses provided redirected from" do
13
- assert_equal ["URL"], Aitch::Response.new({redirected_from: ["URL"]}, stub("response")).redirected_from
16
+ response =
17
+ Aitch::Response.new(
18
+ {redirected_from: ["URL"]},
19
+ stub("response", content_type: "text/html")
20
+ )
21
+
22
+ assert_equal ["URL"], response.redirected_from
14
23
  end
15
24
 
16
25
  test "has body" do
17
26
  register_uri(:get, "http://example.org/", body: "Hello", status: 301)
18
27
  response = Aitch.get("http://example.org/")
28
+
19
29
  assert_equal "Hello", response.body
20
30
  end
21
31
 
@@ -23,20 +33,21 @@ class Status3xxTest < Minitest::Test
23
33
  register_uri(:get, "http://example.org/", status: 301)
24
34
  response = Aitch.get("http://example.org/")
25
35
 
26
- assert response.success?
27
- assert response.ok?
36
+ assert_predicate response, :success?
37
+ assert_predicate response, :ok?
28
38
  end
29
39
 
30
40
  test "detects as redirect" do
31
41
  register_uri(:get, "http://example.org/", status: 301)
32
42
  response = Aitch.get("http://example.org/")
33
43
 
34
- assert response.redirect?
44
+ assert_predicate response, :redirect?
35
45
  end
36
46
 
37
47
  test "returns location" do
38
48
  register_uri(:get, "http://example.org/", status: 301, location: "https://example.com/")
39
49
  response = Aitch.get("http://example.org/")
50
+
40
51
  assert_equal "https://example.com/", response.location
41
52
  end
42
53
 
@@ -7,7 +7,7 @@ class Status4xxTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", status: 404)
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.error?
10
+ assert_predicate response, :error?
11
11
  end
12
12
 
13
13
  test "sets error" do
@@ -7,7 +7,7 @@ class Status5xxTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", status: 500)
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.error?
10
+ assert_predicate response, :error?
11
11
  end
12
12
 
13
13
  test "sets error" do
@@ -7,7 +7,7 @@ class XmlResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "[]", content_type: "application/xml")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.xml?
10
+ assert_predicate response, :xml?
11
11
  end
12
12
 
13
13
  test "returns xml" do
@@ -6,12 +6,14 @@ class ResponseTest < Minitest::Test
6
6
  test "has body" do
7
7
  register_uri(:get, "http://example.org/", body: "Hello")
8
8
  response = Aitch.get("http://example.org/")
9
+
9
10
  assert_equal "Hello", response.body
10
11
  end
11
12
 
12
13
  test "sets current url" do
13
14
  register_uri(:get, "http://example.org/", body: "Hello")
14
15
  response = Aitch.get("http://example.org/")
16
+
15
17
  assert_equal "http://example.org/", response.url
16
18
  end
17
19
 
@@ -39,19 +41,22 @@ class ResponseTest < Minitest::Test
39
41
  test "returns status code" do
40
42
  register_uri(:get, "http://example.org/", body: "")
41
43
  response = Aitch.get("http://example.org/")
44
+
42
45
  assert_equal 200, response.code
43
46
  end
44
47
 
45
48
  test "returns content type" do
46
49
  register_uri(:get, "http://example.org/", content_type: "text/html")
47
50
  response = Aitch.get("http://example.org/")
51
+
48
52
  assert_equal "text/html", response.content_type
49
53
  end
50
54
 
51
55
  test "detects as successful response" do
52
56
  register_uri(:get, "http://example.org/", content_type: "text/html")
53
57
  response = Aitch.get("http://example.org/")
54
- assert response.success?
58
+
59
+ assert_predicate response, :success?
55
60
  end
56
61
 
57
62
  test "returns headers" do
@@ -74,7 +79,7 @@ class ResponseTest < Minitest::Test
74
79
  response = Aitch.get("http://example.org/")
75
80
 
76
81
  assert_equal "0.003", response.runtime
77
- assert response.respond_to?(:runtime)
82
+ assert_respond_to response, :runtime
78
83
  end
79
84
 
80
85
  test "raises when have no method" do
@@ -33,6 +33,7 @@ class UriTest < Minitest::Test
33
33
 
34
34
  test "returns request uri" do
35
35
  uri = Aitch::URI.new("http://example.org/some/path?a=1&b=2#hello", c: 3)
36
+
36
37
  assert_equal "/some/path?a=1&b=2&c=3#hello", uri.request_uri
37
38
  end
38
39
  end
@@ -5,6 +5,7 @@ require "test_helper"
5
5
  class SymbolizeKeysTest < Minitest::Test
6
6
  test "converts keys to symbols" do
7
7
  expected = {a: 1}
8
+
8
9
  assert_equal expected, Aitch::Utils.symbolize_keys("a" => 1)
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-13 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -248,14 +248,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
248
  requirements:
249
249
  - - ">="
250
250
  - !ruby/object:Gem::Version
251
- version: 2.5.0
251
+ version: 3.0.0
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - ">="
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  requirements: []
258
- rubygems_version: 3.3.7
258
+ rubygems_version: 3.4.6
259
259
  signing_key:
260
260
  specification_version: 4
261
261
  summary: A simple HTTP client