-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Header matching inconsistency with strict_mode and verify_stubbed_calls #1488
Comments
Hi, thank you for reporting the issue. There might be problems on faraday/lib/faraday/utils/headers.rb Lines 57 to 63 in f6c3868
Also, testing adapter does not type-cast non- I think you don't have to explicitly set headers = { 'Content-Type' => 'application/json' }
client.adapter(:test) do |stub|
stub.post('/api/push', '{}', headers) { [200, {}, {}] }
stub.strict_mode = true
end Here is the change: diff --git a/a.rb b/a.rb
index a0a1cba..ef6599a 100644
--- a/a.rb
+++ b/a.rb
@@ -1,6 +1,6 @@
-headers = { 'Content-Type': 'application/json' }
+headers = { 'Content-Type' => 'application/json' }
client.adapter(:test) do |stub|
- stub.post('/api/push', {}, headers) { [200, {}, {}] }
+ stub.post('/api/push', '{}', headers) { [200, {}, {}] }
stub.strict_mode = true
end |
Hi @yykamei. Yes, that also works. The bug though is that you'd want
|
Actually, we're both partly right. It is indeed that symbols aren't supported in the testing framework. So your headers change works. But,
Thanks for your help. I don't know if this should just be closed? Maybe others would get tripped up by the symbol comparison. |
Maybe, I understood your point; the testing adapter should consider the JSON middleware when comparing the actually used request header with expected one. If developers use |
Basic Info
Issue description
When adding rspec tests using Faraday's test facility, an error is falsely raised when the following are true:
request(:json)
is set'Content-Type': 'application/json'
is set in a:test
adapter stubuse_strict = true
is set in the:test
adapterverify_stubbed_calls
is calledThe resulting error is:
This appears to be due to inconsistent header case normalization and case sensitive header matching in strict stubs.
Explicitly setting the
Content-type
header (with lowercase-type
) is a workaround like so:Steps to reproduce
Create a faraday object like so:
Set the expected stubs:
Use the client:
Run
verify_stubbed_calls
and observe the unexpected failure:The text was updated successfully, but these errors were encountered: