<commit_before>shared_examples_for "stubbing requests" do |*adapter_info|
  describe "when requests are stubbed" do
    describe "based on uri" do
      it "should return stubbed response even if request have escaped parameters" do
        stub_request(:get, "www.example.com/hello/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should return stubbed response even if request has non escaped params" do
        stub_request(:get, "www.example.com/hello/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should return stubbed response even if stub uri is declared as regexp and request params are escaped" do
        stub_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should raise error specifying stubbing instructions with escaped characters in params if there is no matching stub" do
        begin
          http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}")
        rescue WebMock::NetConnectNotAllowedError => e
          e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m
          e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m
        end

        stub_request(:get, "http://www.example.com/hello/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
        http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}")<commit_msg>Added spec to ensure + in uri path is correctly handled by WebMock.<commit_after>shared_examples_for "stubbing requests" do |*adapter_info|
  describe "when requests are stubbed" do
    describe "based on uri" do
      it "should return stubbed response even if request have escaped parameters" do
        stub_request(:get, "www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello%2B/?#{ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should return stubbed response even if request has non escaped params" do
        stub_request(:get, "www.example.com/hello%2B/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should return stubbed response even if stub uri is declared as regexp and request params are escaped" do
        stub_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
        http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
      end

      it "should raise error specifying stubbing instructions with escaped characters in params if there is no matching stub" do
        begin
          http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
        rescue WebMock::NetConnectNotAllowedError => e
          e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m
          e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m
        end

        stub_request(:get, "http://www.example.com/hello+/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
        http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
{'fraction_non_alphanumeric': 0.1580104424292388, 'fraction_numerical': 0.013740038472107722, 'mean_word_length': 3.56140350877193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 20, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389973', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1188, 'n_words': 254}