Skip to content

Commit 78c8fb0

Browse files
committed
Add #url and make #to_hash return Hash of which values are empty
1 parent f9e4ff5 commit 78c8fb0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/faraday/response.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def body
3333
finished? ? env.body : nil
3434
end
3535

36+
def url
37+
finished? ? env.url : nil
38+
end
39+
3640
def finished?
3741
!!env
3842
end
@@ -59,12 +63,10 @@ def success?
5963
end
6064

6165
def to_hash
62-
return {} unless finished?
63-
6466
{
65-
status: env.status, body: env.body,
66-
response_headers: env.response_headers,
67-
url: env.url
67+
status: status, body: body,
68+
response_headers: headers,
69+
url: url
6870
}
6971
end
7072

spec/faraday/response_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
it { expect(subject.success?).to be_falsey }
1414
it { expect(subject.status).to eq(404) }
1515
it { expect(subject.body).to eq('yikes') }
16+
it { expect(subject.url).to eq(URI('https://lostisland.github.io/faraday')) }
1617
it { expect(subject.headers['Content-Type']).to eq('text/plain') }
1718
it { expect(subject['content-type']).to eq('text/plain') }
1819

@@ -35,7 +36,7 @@
3536
context 'when response is not finished' do
3637
subject { Faraday::Response.new.to_hash }
3738

38-
it { is_expected.to eq({}) }
39+
it { is_expected.to eq({ status: nil, body: nil, response_headers: {}, url: nil }) }
3940
end
4041
end
4142

0 commit comments

Comments
 (0)