File tree 3 files changed +15
-5
lines changed
3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ def response_body
52
52
# :body - Optional string HTTP response body.
53
53
# :request - Hash
54
54
# :method - Symbol with the request HTTP method.
55
+ # :url - URI object with the url requested.
55
56
# :url_path - String with the url path requested.
56
57
# :params - String key/value hash of query params
57
58
# present in the request.
Original file line number Diff line number Diff line change @@ -44,13 +44,19 @@ def response_values(env)
44
44
body : env . body ,
45
45
request : {
46
46
method : env . method ,
47
+ url : env . url ,
47
48
url_path : env . url . path ,
48
- params : env . params ,
49
+ params : query_params ( env ) ,
49
50
headers : env . request_headers ,
50
51
body : env . request_body
51
52
}
52
53
}
53
54
end
55
+
56
+ def query_params ( env )
57
+ env . request . params_encoder ||= Faraday ::Utils . default_params_encoder
58
+ env . params_encoder . decode ( env . url . query )
59
+ end
54
60
end
55
61
end
56
62
end
Original file line number Diff line number Diff line change 139
139
Faraday . new do |b |
140
140
b . response :raise_error
141
141
b . adapter :test do |stub |
142
- stub . post ( 'request?full=true' , request_body , request_headers ) do
142
+ stub . post ( url , request_body , request_headers ) do
143
143
[ 400 , { 'X-Reason' => 'because' } , 'keep looking' ]
144
144
end
145
145
end
146
146
end
147
147
end
148
148
let ( :request_body ) { JSON . generate ( { 'item' => 'sth' } ) }
149
149
let ( :request_headers ) { { 'Authorization' => 'Basic 123' } }
150
+ let ( :url_path ) { 'request' }
151
+ let ( :query_params ) { 'full=true' }
152
+ let ( :url ) { "#{ url_path } ?#{ query_params } " }
150
153
151
154
subject ( :perform_request ) do
152
- conn . post 'request' do |req |
155
+ conn . post url do |req |
153
156
req . headers [ 'Authorization' ] = 'Basic 123'
154
- req . params [ :full ] = true
155
157
req . body = request_body
156
158
end
157
159
end
158
160
159
161
it 'returns the request info in the exception' do
160
162
expect { perform_request } . to raise_error ( Faraday ::BadRequestError ) do |ex |
161
163
expect ( ex . response [ :request ] [ :method ] ) . to eq ( :post )
162
- expect ( ex . response [ :request ] [ :url_path ] ) . to eq ( '/request' )
164
+ expect ( ex . response [ :request ] [ :url ] ) . to eq ( URI ( "http:/#{ url } " ) )
165
+ expect ( ex . response [ :request ] [ :url_path ] ) . to eq ( "/#{ url_path } " )
163
166
expect ( ex . response [ :request ] [ :params ] ) . to eq ( { 'full' => 'true' } )
164
167
expect ( ex . response [ :request ] [ :headers ] ) . to match ( a_hash_including ( request_headers ) )
165
168
expect ( ex . response [ :request ] [ :body ] ) . to eq ( request_body )
You can’t perform that action at this time.
0 commit comments