lhc 3.4.0 → 3.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 +4 -4
- data/.rubocop.localch.yml +190 -0
- data/.rubocop.yml +10 -0
- data/cider-ci.yml +2 -1
- data/cider-ci/jobs/rspec.yml +48 -0
- data/cider-ci/jobs/rubocop.yml +55 -0
- data/cider-ci/scripts/bundle.yml +2 -0
- data/cider-ci/scripts/github_comment.yml +6 -0
- data/cider-ci/scripts/rspec.yml +4 -0
- data/cider-ci/scripts/rubocop.yml +5 -0
- data/cider-ci/scripts/ruby-version.yml +2 -0
- data/cider-ci/scripts/tmp-cache.yml +2 -0
- data/lhc.gemspec +2 -1
- data/lib/lhc.rb +1 -1
- data/lib/lhc/concerns/lhc/basic_methods.rb +4 -6
- data/lib/lhc/concerns/lhc/formats.rb +0 -2
- data/lib/lhc/endpoint.rb +8 -6
- data/lib/lhc/error.rb +3 -1
- data/lib/lhc/errors/parser_error.rb +4 -0
- data/lib/lhc/formats/json.rb +18 -4
- data/lib/lhc/interceptor.rb +2 -0
- data/lib/lhc/interceptor_processor.rb +1 -1
- data/lib/lhc/request.rb +12 -10
- data/lib/lhc/response.rb +3 -9
- data/lib/lhc/version.rb +1 -1
- data/non_rails_spec/request/request_spec.rb +2 -2
- data/spec/basic_methods/delete_spec.rb +4 -6
- data/spec/basic_methods/get_spec.rb +3 -6
- data/spec/basic_methods/post_spec.rb +7 -9
- data/spec/basic_methods/put_spec.rb +7 -9
- data/spec/basic_methods/request_spec.rb +2 -4
- data/spec/config/endpoints_spec.rb +13 -16
- data/spec/config/placeholders_spec.rb +9 -11
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/initializers/cookies_serializer.rb +1 -1
- data/spec/endpoint/compile_spec.rb +3 -5
- data/spec/endpoint/match_spec.rb +10 -12
- data/spec/endpoint/placeholders_spec.rb +1 -3
- data/spec/endpoint/remove_interpolated_params_spec.rb +2 -3
- data/spec/endpoint/values_as_params_spec.rb +2 -4
- data/spec/error/find_spec.rb +37 -39
- data/spec/error/response_spec.rb +0 -2
- data/spec/error/timeout_spec.rb +1 -3
- data/spec/interceptors/after_request_spec.rb +2 -4
- data/spec/interceptors/after_response_spec.rb +3 -5
- data/spec/interceptors/before_request_spec.rb +2 -4
- data/spec/interceptors/before_response_spec.rb +2 -4
- data/spec/interceptors/default_interceptors_spec.rb +3 -5
- data/spec/interceptors/define_spec.rb +4 -6
- data/spec/interceptors/response_competition_spec.rb +6 -7
- data/spec/interceptors/return_response_spec.rb +8 -11
- data/spec/request/encoding_spec.rb +1 -4
- data/spec/request/error_handling_spec.rb +13 -2
- data/spec/request/headers_spec.rb +1 -2
- data/spec/request/option_dup_spec.rb +2 -3
- data/spec/request/parallel_requests_spec.rb +2 -2
- data/spec/request/url_patterns_spec.rb +4 -5
- data/spec/response/body_spec.rb +2 -4
- data/spec/response/code_spec.rb +2 -4
- data/spec/response/data_spec.rb +2 -4
- data/spec/response/effective_url_spec.rb +1 -3
- data/spec/response/headers_spec.rb +2 -4
- data/spec/response/options_spec.rb +2 -4
- data/spec/response/success_spec.rb +2 -3
- data/spec/response/time_spec.rb +3 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/support/reset_config.rb +0 -2
- data/spec/timeouts/no_signal_spec.rb +1 -3
- data/spec/timeouts/timings_spec.rb +27 -33
- metadata +27 -4
- data/cider-ci/contexts/rspec.yml +0 -19
- data/cider-ci/jobs/tests.yml +0 -27
data/spec/dummy/bin/rails
CHANGED
data/spec/dummy/config.ru
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
|
-
|
5
4
|
context 'compile' do
|
6
|
-
|
7
5
|
it 'uses parameters for interpolation' do
|
8
|
-
endpoint =
|
6
|
+
endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
|
9
7
|
expect(
|
10
8
|
endpoint.compile(datastore: 'http://datastore', campaign_id: 'abc')
|
11
9
|
).to eq "http://datastore/v2/abc/feedbacks"
|
12
10
|
end
|
13
11
|
|
14
12
|
it 'uses provided proc to find values' do
|
15
|
-
endpoint =
|
13
|
+
endpoint = described_class.new(':datastore/v2')
|
16
14
|
config = { datastore: 'http://datastore' }
|
17
|
-
find_value =
|
15
|
+
find_value = lambda { |match|
|
18
16
|
config[match.gsub(':', '').to_sym]
|
19
17
|
}
|
20
18
|
expect(
|
data/spec/endpoint/match_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
|
-
|
5
4
|
context 'match' do
|
6
|
-
|
7
5
|
context 'matching' do
|
8
6
|
it 'checks if a url matches a template' do
|
9
7
|
{
|
@@ -12,23 +10,23 @@ describe LHC::Endpoint do
|
|
12
10
|
':datastore/v2/places/:namespace/:id' => 'http://local.ch:8082/v2/places/switzerland/ZW9OJyrbt'
|
13
11
|
}.each do |template, url|
|
14
12
|
expect(
|
15
|
-
|
13
|
+
described_class.match?(url, template)
|
16
14
|
).to be, "#{url} should match #{template}!"
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
context 'not matching' do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
20
|
+
it 'checks if a url matches a template' do
|
21
|
+
{
|
22
|
+
':datastore/v2/places' => 'http://local.ch:8082/v2/places/ZW9OJyrbt4OZE9ueu80w-A',
|
23
|
+
':datastore/:campaign_id/feedbacks' => 'http://datastore.local.ch/feedbacks'
|
24
|
+
}.each do |template, url|
|
25
|
+
expect(
|
26
|
+
described_class.match?(url, template)
|
27
|
+
).not_to be, "#{url} should not match #{template}!"
|
31
28
|
end
|
29
|
+
end
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
|
-
|
5
4
|
context 'placeholders' do
|
6
|
-
|
7
5
|
it 'returns all placeholders alphabetically sorted' do
|
8
|
-
endpoint =
|
6
|
+
endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
|
9
7
|
expect(
|
10
8
|
endpoint.placeholders
|
11
9
|
).to eq [':campaign_id', ':datastore']
|
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
|
-
|
5
4
|
it 'removes params used for interpolation' do
|
6
5
|
params = {
|
7
6
|
datastore: 'http://datastore',
|
8
7
|
campaign_id: 'abc',
|
9
8
|
has_reviews: true
|
10
9
|
}
|
11
|
-
endpoint =
|
10
|
+
endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
|
12
11
|
removed = endpoint.remove_interpolated_params!(params)
|
13
|
-
expect(params).to eq
|
12
|
+
expect(params).to eq(has_reviews: true)
|
14
13
|
expect(removed).to eq(datastore: 'http://datastore', campaign_id: 'abc')
|
15
14
|
end
|
16
15
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
|
-
|
5
4
|
context 'values_as_params' do
|
6
|
-
|
7
5
|
it 'provides params extracting values from a provided url and template' do
|
8
6
|
[
|
9
7
|
[':datastore/v2/places', 'http://local.ch:8082/v2/places', {
|
@@ -17,9 +15,9 @@ describe LHC::Endpoint do
|
|
17
15
|
datastore: 'http://local.ch:8082',
|
18
16
|
namespace: 'switzerland',
|
19
17
|
id: 'ZW9OJyrbt'
|
20
|
-
}]
|
18
|
+
}]
|
21
19
|
].each do |example|
|
22
|
-
params =
|
20
|
+
params = described_class.values_as_params(example[0], example[1])
|
23
21
|
expect(params).to eq example[2]
|
24
22
|
end
|
25
23
|
end
|
data/spec/error/find_spec.rb
CHANGED
@@ -1,56 +1,54 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Error do
|
4
|
-
|
5
4
|
def response(code)
|
6
|
-
LHC::Response.new(OpenStruct.new(
|
5
|
+
LHC::Response.new(OpenStruct.new(code: code), nil)
|
7
6
|
end
|
8
7
|
|
9
8
|
context 'find' do
|
10
|
-
|
11
9
|
it 'finds error class by status code' do
|
12
|
-
expect(
|
13
|
-
expect(
|
14
|
-
expect(
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
expect(
|
22
|
-
expect(
|
23
|
-
expect(
|
24
|
-
expect(
|
25
|
-
expect(
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
10
|
+
expect(described_class.find(response('400'))).to eq LHC::BadRequest
|
11
|
+
expect(described_class.find(response('401'))).to eq LHC::Unauthorized
|
12
|
+
expect(described_class.find(response('402'))).to eq LHC::PaymentRequired
|
13
|
+
expect(described_class.find(response('403'))).to eq LHC::Forbidden
|
14
|
+
expect(described_class.find(response('403'))).to eq LHC::Forbidden
|
15
|
+
expect(described_class.find(response('404'))).to eq LHC::NotFound
|
16
|
+
expect(described_class.find(response('405'))).to eq LHC::MethodNotAllowed
|
17
|
+
expect(described_class.find(response('406'))).to eq LHC::NotAcceptable
|
18
|
+
expect(described_class.find(response('407'))).to eq LHC::ProxyAuthenticationRequired
|
19
|
+
expect(described_class.find(response('408'))).to eq LHC::RequestTimeout
|
20
|
+
expect(described_class.find(response('409'))).to eq LHC::Conflict
|
21
|
+
expect(described_class.find(response('410'))).to eq LHC::Gone
|
22
|
+
expect(described_class.find(response('411'))).to eq LHC::LengthRequired
|
23
|
+
expect(described_class.find(response('412'))).to eq LHC::PreconditionFailed
|
24
|
+
expect(described_class.find(response('413'))).to eq LHC::RequestEntityTooLarge
|
25
|
+
expect(described_class.find(response('414'))).to eq LHC::RequestUriToLong
|
26
|
+
expect(described_class.find(response('415'))).to eq LHC::UnsupportedMediaType
|
27
|
+
expect(described_class.find(response('416'))).to eq LHC::RequestedRangeNotSatisfiable
|
28
|
+
expect(described_class.find(response('417'))).to eq LHC::ExpectationFailed
|
29
|
+
expect(described_class.find(response('422'))).to eq LHC::UnprocessableEntity
|
30
|
+
expect(described_class.find(response('423'))).to eq LHC::Locked
|
31
|
+
expect(described_class.find(response('424'))).to eq LHC::FailedDependency
|
32
|
+
expect(described_class.find(response('426'))).to eq LHC::UpgradeRequired
|
33
|
+
expect(described_class.find(response('500'))).to eq LHC::InternalServerError
|
34
|
+
expect(described_class.find(response('501'))).to eq LHC::NotImplemented
|
35
|
+
expect(described_class.find(response('502'))).to eq LHC::BadGateway
|
36
|
+
expect(described_class.find(response('503'))).to eq LHC::ServiceUnavailable
|
37
|
+
expect(described_class.find(response('504'))).to eq LHC::GatewayTimeout
|
38
|
+
expect(described_class.find(response('505'))).to eq LHC::HttpVersionNotSupported
|
39
|
+
expect(described_class.find(response('507'))).to eq LHC::InsufficientStorage
|
40
|
+
expect(described_class.find(response('510'))).to eq LHC::NotExtended
|
43
41
|
end
|
44
42
|
|
45
43
|
it 'finds error class also by extended status codes' do
|
46
|
-
expect(
|
47
|
-
expect(
|
44
|
+
expect(described_class.find(response('40001'))).to eq LHC::BadRequest
|
45
|
+
expect(described_class.find(response('50002'))).to eq LHC::InternalServerError
|
48
46
|
end
|
49
47
|
|
50
48
|
it 'returns UnknownError if no specific error was found' do
|
51
|
-
expect(
|
52
|
-
expect(
|
53
|
-
expect(
|
49
|
+
expect(described_class.find(response('0'))).to eq LHC::UnknownError
|
50
|
+
expect(described_class.find(response(''))).to eq LHC::UnknownError
|
51
|
+
expect(described_class.find(response('600'))).to eq LHC::UnknownError
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
data/spec/error/response_spec.rb
CHANGED
data/spec/error/timeout_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC::Error do
|
4
|
-
|
5
4
|
context 'timeout' do
|
6
|
-
|
7
5
|
it 'throws timeout exception in case of a timeout' do
|
8
6
|
stub_request(:any, 'local.ch').to_timeout
|
9
|
-
expect(
|
7
|
+
expect(lambda {
|
10
8
|
LHC.get('local.ch')
|
11
9
|
}).to raise_error LHC::Timeout
|
12
10
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
6
|
class SomeInterceptor < LHC::Interceptor
|
9
7
|
def after_request(request)
|
10
8
|
end
|
11
9
|
end
|
12
|
-
|
10
|
+
described_class.configure { |c| c.interceptors = [SomeInterceptor] }
|
13
11
|
end
|
14
12
|
|
15
13
|
it 'can perform some actions after a request was fired' do
|
16
14
|
expect_any_instance_of(SomeInterceptor).to receive(:after_request)
|
17
15
|
stub_request(:get, 'http://local.ch')
|
18
|
-
|
16
|
+
described_class.get('http://local.ch')
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
6
|
class Services
|
9
|
-
def self.timing(
|
7
|
+
def self.timing(_path, _time)
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -27,7 +25,7 @@ describe LHC do
|
|
27
25
|
Services.timing(path.downcase, response.time)
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
28
|
+
described_class.configure { |c| c.interceptors = [StatsTimingInterceptor] }
|
31
29
|
end
|
32
30
|
|
33
31
|
let(:url) { "http://local.ch/v2/feedbacks/-Sc4_pYNpqfsudzhtivfkA" }
|
@@ -35,7 +33,7 @@ describe LHC do
|
|
35
33
|
it 'can take action after a response was received' do
|
36
34
|
allow(Services).to receive(:timing).with('web.dummy.test.get.http.local.ch.200', 0)
|
37
35
|
stub_request(:get, url)
|
38
|
-
|
36
|
+
described_class.get(url)
|
39
37
|
expect(Services).to have_received(:timing)
|
40
38
|
end
|
41
39
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
6
|
class TrackingIdInterceptor < LHC::Interceptor
|
9
7
|
def before_request(request)
|
10
8
|
request.params[:tid] = 123
|
11
9
|
end
|
12
10
|
end
|
13
|
-
|
11
|
+
described_class.configure { |c| c.interceptors = [TrackingIdInterceptor] }
|
14
12
|
end
|
15
13
|
|
16
14
|
it 'can modify requests before they are send' do
|
17
15
|
stub_request(:get, "http://local.ch/?tid=123")
|
18
|
-
|
16
|
+
described_class.get('http://local.ch')
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
6
|
class SomeInterceptor < LHC::Interceptor
|
9
7
|
def before_response(request)
|
10
8
|
end
|
11
9
|
end
|
12
|
-
|
10
|
+
described_class.configure { |c| c.interceptors = [SomeInterceptor] }
|
13
11
|
end
|
14
12
|
|
15
13
|
it 'can perform some actions before a reponse is received' do
|
16
14
|
expect_any_instance_of(SomeInterceptor).to receive(:before_response)
|
17
15
|
stub_request(:get, 'http://local.ch')
|
18
|
-
|
16
|
+
described_class.get('http://local.ch')
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'default interceptors' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
|
-
|
6
|
+
described_class.configure {}
|
9
7
|
end
|
10
8
|
|
11
|
-
it '
|
12
|
-
expect(
|
9
|
+
it 'alwayses return a list for default interceptors' do
|
10
|
+
expect(described_class.config.interceptors).to eq []
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
6
|
class SomeInterceptor < LHC::Interceptor
|
9
7
|
end
|
@@ -12,18 +10,18 @@ describe LHC do
|
|
12
10
|
end
|
13
11
|
|
14
12
|
it 'performs interceptor when they are set globally' do
|
15
|
-
|
13
|
+
described_class.configure { |c| c.interceptors = [SomeInterceptor] }
|
16
14
|
expect_any_instance_of(SomeInterceptor).to receive(:before_request)
|
17
15
|
stub_request(:get, 'http://local.ch')
|
18
|
-
|
16
|
+
described_class.get('http://local.ch')
|
19
17
|
end
|
20
18
|
|
21
19
|
it 'overrides interceptors on request level' do
|
22
|
-
|
20
|
+
described_class.configure { |c| c.interceptors = [SomeInterceptor] }
|
23
21
|
expect_any_instance_of(AnotherInterceptor).to receive(:before_request)
|
24
22
|
expect_any_instance_of(SomeInterceptor).not_to receive(:before_request)
|
25
23
|
stub_request(:get, 'http://local.ch')
|
26
|
-
|
24
|
+
described_class.get('http://local.ch', interceptors: [AnotherInterceptor])
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHC do
|
4
|
-
|
5
4
|
context 'interceptor response competition' do
|
6
|
-
|
7
5
|
before(:each) do
|
8
|
-
|
6
|
+
# rubocop:disable Style/ClassVars
|
9
7
|
class LocalCacheInterceptor < LHC::Interceptor
|
10
8
|
@@cached = false
|
11
9
|
cattr_accessor :cached
|
12
10
|
|
13
|
-
def before_request(
|
11
|
+
def before_request(_request)
|
14
12
|
if @@cached
|
15
13
|
return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from local cache'), nil)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
17
|
+
# rubocop:enable Style/ClassVars
|
19
18
|
|
20
19
|
class RemoteCacheInterceptor < LHC::Interceptor
|
21
20
|
|
@@ -26,14 +25,14 @@ describe LHC do
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
described_class.configure { |c| c.interceptors = [LocalCacheInterceptor, RemoteCacheInterceptor] }
|
30
29
|
end
|
31
30
|
|
32
31
|
it 'can handle multiple interceptors that compete for returning the response' do
|
33
|
-
response =
|
32
|
+
response = described_class.get('http://local.ch')
|
34
33
|
expect(response.body).to eq 'Im served from remote cache'
|
35
34
|
LocalCacheInterceptor.cached = true
|
36
|
-
response =
|
35
|
+
response = described_class.get('http://local.ch')
|
37
36
|
expect(response.body).to eq 'Im served from local cache'
|
38
37
|
end
|
39
38
|
end
|