我如何为...编写RSpec
Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT).start(url.host) do |http|
request = Net::HTTP::Post.new(url.path)
request.form_data = {'param1' => 'blah1', 'param2' => 'blah2'}
response = http.request(request)
end
Run Code Online (Sandbox Code Playgroud)
据我所知...
@mock_http = mock('http')
@mock_http.should_receive(:start).with(@url.host)
Net::HTTP.should_receive(:Proxy).with(PROXY_HOST, PROXY_PORT).and_return(@mock_http)
Net::HTTP::Post.should_receive(:new).with(@url.path).and_return(@mock_http)
Run Code Online (Sandbox Code Playgroud)
但是当尝试...
Net::HTTP::Post.should_receive(:new).with(@url.path).and_return(@mock_http)
Run Code Online (Sandbox Code Playgroud)
...收到以下回应...
<Net::HTTP::Post (class)> expected :new with ("/some/path") once, but received it 0 times
Run Code Online (Sandbox Code Playgroud)
完整的解决方案将不胜感激!