Draft: Fix test to ensure mock behavior is always preserved
What does this MR do and why?
Fix test to ensure mock behavior is always preserved .
Related comment: !98656 (comment 1137130322)
To solove Rubocop role Security/Open
, replaced URI.open(GHFM_SPEC_TXT_URI)
to URI.parse(GHFM_SPEC_TXT_URI).open
in MR(!98656 (merged)).
Original test code:
allow(URI).to receive(:open).with(ghfm_spec_txt_uri) { ghfm_spec_txt_uri_io }
Replaced test code:
allow_next_instance_of(URI::HTTP) do |instance|
allow(instance).to receive(:open).and_return(ghfm_spec_txt_uri_io)
end
The coverage for the parameter ghfm_spec_txt_uri
is missing here.
Fix test to ensure mock behavior is always preserved.
Updated test code:
allow(URI).to receive(:open).with(ghfm_spec_txt_uri).and_call_original
allow_next_instance_of(URI::HTTP) do |instance|
allow(instance).to receive(:open).and_return(ghfm_spec_txt_uri_io)
end
Edited by Baodong