Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个 gem,我想检查它是否正在使用它应该传递的参数、标头和内容执行 http 请求。如何编写单元测试。
我正在使用 httparty 来执行请求,我也在使用 fakeweb 来测试响应后的操作。
我建议使用 webmock 并包含应该创建的存根请求:
在您的 Gemfile 中:
group :test do gem 'webmock' end
在您的规格中:
stub_request(:post, "https://external.api.com") .with(:body => {:message => {:foo => 'bar'}}, :headers => {'Accept'=>'application/json'})