Skip to content

Commit

Permalink
Add Request#inspect method
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Jan 18, 2019
1 parent 76a9f69 commit 5c49118
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ def socket_port
using_proxy? ? proxy[:proxy_port] : port
end

# Human-readable representation of base request info.
#
# @example
#
# req.inspect
# # => #<HTTP::Request/1.1 GET https://example.com>
#
# @return [String]
def inspect
"#<#{self.class}/#{@version} #{verb.to_s.upcase} #{uri}>"
end

private

# @!attribute [r] host
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,10 @@
end
end
end

describe "#inspect" do
subject { request.inspect }

it { is_expected.to eq "#<HTTP::Request/1.1 GET #{request_uri}>" }
end
end
7 changes: 3 additions & 4 deletions spec/lib/http/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@
end

describe "#inspect" do
subject { response.inspect }

let(:headers) { {:content_type => "text/plain"} }
let(:body) { double :to_s => "foobar" }

it "returns human-friendly response representation" do
expect(response.inspect).
to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>'
end
it { is_expected.to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>' }
end

describe "#cookies" do
Expand Down

0 comments on commit 5c49118

Please sign in to comment.