<commit_before>require_relative '../../../spec_helper'

require 'rspec/core'
require 'rspec/expectations'
require 'rspec/mocks'
require 'mocha'
require_relative '../../../../lib/carto/http/client'
require_relative '../../../../lib/carto/http/request'

describe Carto::Http::Client do

  before(:each) do
    http_client_tag = 'test'
    @client = Carto::Http::Client.get(http_client_tag, log_requests: true)
  end


  describe '#request' do
    it 'wraps creation of typhoeus request objects' do
      expected_url = 'www.example.com'
      expected_options = {
        method: :post,
        body: "this is a request body",
        params: { field1: "a field" },
        headers: { Accept: "text/html", 
                  "User-Agent" => Carto::Http::Request::DEFAULT_USER_AGENT 
                }
      }
      Typhoeus::Request.expects(:new).once.with(expected_url, expected_options)
      @client.request(
                     "www.example.com",
                     method: :post,
                     body: "this is a request body",
                     params: { field1: "a field" },
                     headers: { Accept: "text/html", "User-Agent" => Carto::Http::Request::DEFAULT_USER_AGENT}
                     )
    end
  end

  describe 'Request#run' do
    it 'performs a request through its typhoeus request object' do
      expected_response = Typhoeus::Response.new(code: 200, body: "{'name' : 'paul'}")
      Typhoeus.stub('www.example.com').and_return(expected_response)
      request = @client.request(<commit_msg>Clear Typhoeus expectations/stubs between tests<commit_after>require_relative '../../../spec_helper'

require 'rspec/core'
require 'rspec/expectations'
require 'rspec/mocks'
require 'mocha'
require_relative '../../../../lib/carto/http/client'
require_relative '../../../../lib/carto/http/request'

describe Carto::Http::Client do

  before(:each) do
    http_client_tag = 'test'
    @client = Carto::Http::Client.get(http_client_tag, log_requests: true)
  end

  after(:each) do
    Typhoeus::Expectation.clear
  end

  describe '#request' do
    it 'wraps creation of typhoeus request objects' do
      expected_url = 'www.example.com'
      expected_options = {
        method: :post,
        body: "this is a request body",
        params: { field1: "a field" },
        headers: { Accept: "text/html", 
                  "User-Agent" => Carto::Http::Request::DEFAULT_USER_AGENT 
                }
      }
      Typhoeus::Request.expects(:new).once.with(expected_url, expected_options)
      @client.request(
                     "www.example.com",
                     method: :post,
                     body: "this is a request body",
                     params: { field1: "a field" },
                     headers: { Accept: "text/html", "User-Agent" => Carto::Http::Request::DEFAULT_USER_AGENT}
                     )
    end
  end

  describe 'Request#run' do
    it 'performs a request through its typhoeus request object' do
      expected_response = Typhoeus::Response.new(code: 200, body: "{'name' : 'paul'}")
      Typhoeus.stub('www.example.com').and_return(expected_response)
      request = @client.request(
{'fraction_non_alphanumeric': 0.13892405063291138, 'fraction_numerical': 0.0031645569620253164, 'mean_word_length': 2.3735325506937035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '650840', 'n_tokens_mistral': 978, 'n_tokens_neox': 944, 'n_words': 211}