-
Notifications
You must be signed in to change notification settings - Fork 0
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
Allow blocks on Faraday connections #1
Conversation
Try this and see if it works: it 'passes a block' do
block = Proc.new { |_, _| }
klass.expects(verb).with(url, args, block).returns(response)
res = klass.send("#{verb}!", url, args, &block)
res.body.must_equal body
end |
@markbates I also tried that and no luck, here's what I get:
|
http://stackoverflow.com/questions/3252046/mock-methods-that-receives-a-block-as-parameter Why not change the test to assert something in the block happens when you call the bang method with a block? That should prove that the block is getting passed through. |
Since Faraday doesn't support the `options` request as a first class HTTP method (see lostisland/faraday#305) we need to use the `run_request` method instead of the `options` one.
I decided to raise errors since it was the only thing I could think of to test without having false possitives, since `assert true` won't fail if the test is not passed.
@markbates I've updated this with two commits:
Please let me know how this looks and thanks a lot. |
@@ -1,22 +1,33 @@ | |||
module Faraday::Bang | |||
ERROR_CODES = [(400..417).to_a, (500..505).to_a].flatten | |||
SUPPORTED_HTTP_METHODS = Faraday::Connection::METHODS - Set.new([ :options ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be more simply written as:
SUPPORTED_HTTP_METHODS = Faraday::Connection::METHODS - [ :options ]
@nhocki looks good. I added a few inline comments on a couple of things. As soon as those are addressed I'll be happy to merge this in. Thanks. |
* Rename `handle_error` for `handle_response` * Remove `define_method` for the `options!` method.
@markbates I added the tests for options but I didn't know how to add them with the same block... This happens because the tests expect for That's pretty much the only difference, so I'd love some help on removing the duplication there. I also addressed your other comments. Thanks, |
At the end of the day it looks like everything calls |
@markbates the problem is that there is no "common" way of calling For |
In that case, screw it. I'm merging it. Thanks so much. Sorry that what should've been a simple PR turned into such a nightmare. |
Allow blocks on Faraday connections
Not a problem at all. Thanks for this gem! Nicolás Hock Isaza On Fri, Feb 6, 2015 at 4:21 PM, Mark Bates notifications@github.com
|
Hey Mark,
I'm adding the ability to use blocks when doing the requests. I have no idea on how to actually add a test for this, I've tried something like this but didn't work:
It does however allow me to do something like this:
I'll gladly add tests if you can point me on how to do this.
Thanks!