Skip to content

Instantly share code, notes, and snippets.

@langalex
Created April 16, 2021 11:12
Show Gist options
  • Save langalex/f2a4cdb3f6a768560f0188efdd1951bc to your computer and use it in GitHub Desktop.
Save langalex/f2a4cdb3f6a768560f0188efdd1951bc to your computer and use it in GitHub Desktop.
rest-client stub bad request error with RSpec
module RestClientHelpers
def bad_request_error(json_body)
request = double(:request, redirection_history: nil)
net_http_res = double(:response, to_hash: {}, code: 400)
response = RestClient::Response.create(json_body.to_json, net_http_res, request)
RestClient::BadRequest.new response, 400
end
end
RSpec.configure do |c|
c.include RestClientHelpers
end
@davidoram
Copy link

Thanks for sharing this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment