Skip to content

Commit

Permalink
[Fix Neodelf#21] Replace rest-client with http.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
oskaror committed Feb 2, 2022
1 parent 0dc13b6 commit c15ea70
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
44 changes: 25 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@ PATH
remote: .
specs:
lecter (0.1.6)
rest-client
http
simplecov

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
diff-lcs (1.3)
docile (1.3.2)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
http-accept (1.7.0)
http-cookie (1.0.3)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
http (5.0.4)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.4)
domain_name (~> 0.5)
http-form_data (2.3.0)
jaro_winkler (1.5.4)
json (2.3.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
netrc (0.11.0)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
parallel (1.19.1)
parser (2.7.1.0)
ast (~> 2.4.0)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (13.0.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rspec (3.8.0)
rspec-core (~> 3.8.0)
Expand All @@ -55,14 +60,15 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
ruby-progressbar (1.10.1)
simplecov (0.17.1)
simplecov (0.21.2)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unf_ext (0.0.8)
unicode-display_width (1.7.0)

PLATFORMS
Expand Down
2 changes: 1 addition & 1 deletion lecter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'

spec.add_runtime_dependency 'rest-client'
spec.add_runtime_dependency 'http'
spec.add_runtime_dependency 'simplecov'
end
2 changes: 1 addition & 1 deletion lib/lecter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'lecter/version'
require 'lecter/trace_point'

require 'rest-client'
require 'http'

module Lecter
AVAILABLE_METHODS = %w[GET POST PUT PATCH DELETE].freeze
Expand Down
10 changes: 3 additions & 7 deletions lib/lecter/requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call
rescue URI::InvalidURIError
@error_message = WRONG_URL_MSG
false
rescue RestClient::ExceptionWithResponse => e
rescue HTTP::Error => e
@error_message = e.message
false
end
Expand All @@ -43,15 +43,11 @@ def prepare_lines
end

def response
@response ||= RestClient::Request.execute(
method: method,
url: url,
payload: payload
)
@response ||= HTTP.public_send(method, url, body: payload.to_json)
end

def items
@items ||= response.body[3..-1].split(';')
@items ||= response.body.to_s[3..-1].split(';')
end

def line_belongs_to_last?(file)
Expand Down
10 changes: 5 additions & 5 deletions spec/requester_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
let(:specific_parameter) { { lecter_enabled: true } }
let(:url) { 'localhost:3009/posts' }
let(:payload) { { 'post' => { 'title' => 'New title', 'description' => 'New description' } } }
let(:params) { { method: :anything, url: url, payload: payload, lecter_enabled: true } }
let(:params) { { method: :get, url: url, payload: payload, lecter_enabled: true } }
let(:instance) { described_class.new(params) }

subject { instance.call }

context 'if all params are valid' do
before do
response = instance_double(
RestClient::Response,
HTTP::Response,
body: "\
302/absolute_path_to_app/app/controllers/posts_controller.rb 26 PostsController create call;\
/absolute_path_to_app/app/controllers/posts_controller.rb 27 PostsController create line;\
Expand All @@ -28,7 +28,7 @@
/absolute_path_to_app/app/controllers/posts_controller.rb 31 PostsController create line;\
/absolute_path_to_app/app/controllers/posts_controller.rb 38 PostsController create return;"
)
allow(RestClient::Request).to receive(:execute).and_return(response)
allow(HTTP).to receive(:get).and_return(response)
subject
end

Expand All @@ -44,10 +44,10 @@
end
end

[RestClient::ExceptionWithResponse, URI::InvalidURIError].each do |error|
[HTTP::RequestError, URI::InvalidURIError].each do |error|
context "if raise #{error}" do
before do
allow(RestClient::Request).to receive(:execute).and_raise(error)
allow(HTTP).to receive(:get).and_raise(error)
end

it 'returns false' do
Expand Down

0 comments on commit c15ea70

Please sign in to comment.