Skip to content

Commit

Permalink
fix inspect method
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon committed Sep 19, 2024
1 parent ee2925c commit 8dd7111
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ AllCops:
Exclude:
- vendor/**/*

RSpec/Rails/HaveHttpStatus:
RSpec/SpecFilePathFormat:
Enabled: false

RSpec/SpecFilePathFormat:
RSpec/ExpectInLet:
Enabled: false
67 changes: 29 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.4)
activesupport (7.1.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -23,7 +23,7 @@ GEM
base64 (0.2.0)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
coveralls (0.7.2)
multi_json (~> 1.3)
Expand All @@ -42,17 +42,17 @@ GEM
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
hashdiff (1.1.0)
hashdiff (1.1.1)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.5.0)
http-cookie (1.0.6)
http-cookie (1.0.7)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
Expand All @@ -62,12 +62,12 @@ GEM
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0702)
minitest (5.24.1)
mime-types-data (3.2024.0903)
minitest (5.25.1)
multi_json (1.15.0)
mutex_m (0.2.0)
parallel (1.25.1)
parser (3.3.4.0)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
Expand All @@ -81,61 +81,53 @@ GEM
regexp_parser (2.9.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rexml (3.3.2)
strscan
rexml (3.3.7)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.63.5)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-config-umbrellio (1.63.0.93)
rubocop (~> 1.63.0)
rubocop-performance (~> 1.21.0)
rubocop-rails (~> 2.24.0)
rubocop-config-umbrellio (1.66.0.99)
rubocop (~> 1.66.0)
rubocop-factory_bot (~> 2.26.0)
rubocop-performance (~> 1.22.0)
rubocop-rails (~> 2.26.0)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 2.29.0)
rubocop-rspec (~> 3.0.0)
rubocop-sequel (~> 0.3.3)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-performance (1.21.1)
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.24.1)
rubocop-rails (2.26.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.29.1)
rubocop-rspec (3.0.5)
rubocop (~> 1.61)
rubocop-sequel (0.3.4)
rubocop (~> 1.0)
Expand All @@ -144,17 +136,16 @@ GEM
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
strscan (3.1.0)
term-ansicolor (1.2.2)
tins (~> 0.8)
thor (0.18.1)
tins (0.13.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
Expand All @@ -177,4 +168,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.5.16
2.5.18
2 changes: 1 addition & 1 deletion ezclient.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "http", ">= 4"
spec.add_dependency "http", ">= 4"
end
14 changes: 0 additions & 14 deletions lib/ezclient/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ def error?
client_error? || server_error?
end

def inspect
{
req: {
raw: http_request.inspect,
hdrs: http_request.headers,
},
resp: {
raw: http_response.inspect,
hdrs: headers,
body: body,
},
}.to_s
end

def to_s
inspect
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ezclient/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module EzClient
VERSION = "1.7.0"
VERSION = "1.7.1"
end
41 changes: 7 additions & 34 deletions spec/ezclient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,45 +396,18 @@ def self.sign!(*); end

context "object inspectation" do
specify "#inspect" do
expect(response.inspect).to match({
req: {
raw: response.http_request.inspect,
hdrs: response.http_request.headers,
},
resp: {
raw: response.http_response.inspect,
hdrs: response.http_response.headers,
body: response.body,
},
}.to_s)
expect(response.inspect.gsub(/0x\w+/, "0x0000"))
.to eq(<<~TXT.tr("\n", " ").gsub(/\s+/, " ").strip)
#<EzClient::Response:0x0000
@http_response=#<HTTP::Response/1.1 201 Created {}>,
@http_request=#<HTTP::Request/1.1 POST http://example.com/>,
@body="">
TXT
end

specify "#to_s" do
aggregate_failures "<inspect> representation" do
expect(response.inspect).to eq(response.to_s)

# NOTE:
# - for better visual representability;
# - example.com is fetched from `request` object:
# - see request (@http_request.host)
# - see request.verb
# - see request.url
# rubocop:disable Layout/LineEndStringConcatenationIndentation
# rubocop:disable Style/TrailingCommaInArguments
expect(response.inspect).to eq(
"{:req=>{" \
":raw=>\"#<HTTP::Request/1.1 POST http://example.com/>\", " \
":hdrs=>#<HTTP::Headers " \
"{\"User-Agent\"=>\"ezclient/#{EzClient::VERSION}\", " \
"\"Connection\"=>\"close\", " \
"\"Host\"=>\"example.com\"}>}, " \
":resp=>{" \
":raw=>\"#<HTTP::Response/1.1 #{webmock_response[:status]} Created {}>\", " \
":hdrs=>#<HTTP::Headers {}>, " \
":body=>\"\"}}"
)
# rubocop:enable Layout/LineEndStringConcatenationIndentation
# rubocop:enable Style/TrailingCommaInArguments
end
end
end
Expand Down

0 comments on commit 8dd7111

Please sign in to comment.