mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Previously, the Faraday testing adapter compared the request body to the stubbed body just by calling `#==` if the stubbed body is present. Sometimes, I want to check the equality between request and stubbed body in more advanced ways. For example, there is a case that I want to check only the parts of the body are actually passed to Faraday instance like this: ```ruby stubs = Faraday::Adapter::Test::Stubs.new do |stub| stub.post('/foo', '{"name:"YK","created_at":"ANY STRING IS OK"}') { [200, {}, ''] } end connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now)) stubs.verify_stubbed_calls ``` In this case, it's difficult to make tests always pass with `"created_at"` because the value is dynamic. So, I came up with an idea to pass a proc as a stubbed value and compare bodies, inside the proc: ```ruby stubs = Faraday::Adapter::Test::Stubs.new do |stub| check = -> (request_body) { JSON.parse(request_body).slice('name') == { 'name' => 'YK' } } stub.post('/foo', check) { [200, {}, ''] } end connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now)) stubs.verify_stubbed_calls ``` I believe this would be flexible but compatible with the previous behavior.
Faraday Website
This is the root directory of the Faraday Website.
If you want to apply changes to it, please test it locally using Jekyll
.
Here is how:
# Navigate into the /docs folder
$ cd docs
# Install Jekyll dependencies, this bundle is different from Faraday's one.
$ bundle install
# Run the Jekyll server with the Faraday website
$ bundle exec jekyll serve
# The site will now be reachable at http://127.0.0.1:4000/faraday/