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:
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:
Description
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: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:I believe this would be flexible but compatible with the previous behavior.