You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it "test matcher with block", :focus => true do
stub_request(:get, "xxx.com")
10.times do
RestClient.get("xxx.com", :headers => {'Range' => '1-100'})
end
expect(WebMock).to have_requested(:get, "xxx.com")
.with{ |req|
puts "req"
true
}.times(10)
end
I expect the block to be executed 10 times. But only one "req" was printed.
However, if I send different requests each time, the behavior is as expected.
it "test matcher with block", :focus => true do
stub_request(:get, "xxx.com")
10.times do |i|
RestClient.get("xxx.com", :headers => {'Range' => "#{i}-100"})
end
expect(WebMock).to have_requested(:get, "xxx.com")
.with{ |req|
puts "req"
true
}.times(10)
end
What's the problem here?
The text was updated successfully, but these errors were encountered:
After digging into the code, I find out the cause:
RequestRegistry uses a Util::HashCounter to store all the request signatures. When there are two request signatures that equal in the HashCounter, it will only be matched with the request pattern once.
def times_executed(request_pattern)
self.requested_signatures.hash.select { |request_signature, times_executed|
request_pattern.matches?(request_signature)
}.inject(0) {|sum, (_, times_executed)| sum + times_executed }
end
Hi, with the following code:
I expect the block to be executed 10 times. But only one "req" was printed.
However, if I send different requests each time, the behavior is as expected.
What's the problem here?
The text was updated successfully, but these errors were encountered: