<commit_before># encoding: utf-8
require 'tmpdir'
require 'fileutils'
require 'csv'
require_relative '../../../spec/rspec_configuration'
require_relative '../lib/hires_geocoder'


describe CartoDB::HiresGeocoder do

  MOCK_COORDINATES = [38.89037, -77.03196]

  RSpec.configure do |config|
    config.before :each do
      Typhoeus::Expectation.clear
    end
  end

  before(:each) do
    @working_dir = Dir.mktmpdir
    @input_csv_file = path_to '../../table-geocoder/spec/fixtures/nokia_input.csv'
    CartoDB::HiresGeocoder.any_instance.stubs(:config).returns({
        'non_batch_base_url' => 'batch.example.com',
        'app_id' => '',
        'token' => '',
        'mailto' => ''
      })
    @geocoder = CartoDB::HiresGeocoder.new(@input_csv_file, @working_dir)
  end

  after(:each) do
    FileUtils.rm_f @working_dir
  end

  describe '#run' do
    it 'takes every row from input and calss geocode_text on them' do
      rows_to_geocode = ::CSV.read(@input_csv_file, headers: true).length
      @geocoder.expects(:geocode_text).times(rows_to_geocode).returns(MOCK_COORDINATES)
      @geocoder.run
      @geocoder.status.should == 'completed'
    end
  end

  describe '#process_row' do
    it 'increments the number of processed rows by one when called' do
      output_csv_mock = mock<commit_msg>Update hires_geocoder_spec.rb<commit_after># encoding: utf-8
require 'tmpdir'
require 'fileutils'
require 'csv'
require_relative '../../../spec/rspec_configuration'
require_relative '../lib/hires_geocoder'


describe CartoDB::HiresGeocoder do

  MOCK_COORDINATES = [38.89037, -77.03196]

  RSpec.configure do |config|
    config.before :each do
      Typhoeus::Expectation.clear
    end
  end

  before(:each) do
    @working_dir = Dir.mktmpdir
    @input_csv_file = path_to '../../table-geocoder/spec/fixtures/nokia_input.csv'
    CartoDB::HiresGeocoder.any_instance.stubs(:config).returns({
        'non_batch_base_url' => 'batch.example.com',
        'app_id' => '',
        'token' => '',
        'mailto' => ''
      })
    @geocoder = CartoDB::HiresGeocoder.new(@input_csv_file, @working_dir)
  end

  after(:each) do
    FileUtils.rm_f @working_dir
  end

  describe '#run' do
    it 'takes every row from input and calls geocode_text on them' do
      rows_to_geocode = ::CSV.read(@input_csv_file, headers: true).length
      @geocoder.expects(:geocode_text).times(rows_to_geocode).returns(MOCK_COORDINATES)
      @geocoder.run
      @geocoder.status.should == 'completed'
    end
  end

  describe '#process_row' do
    it 'increments the number of processed rows by one when called' do
      output_csv_mock = mock
{'fraction_non_alphanumeric': 0.12575987841945288, 'fraction_numerical': 0.011398176291793313, 'mean_word_length': 3.4252100840336133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2226424', 'n_tokens_mistral': 968, 'n_tokens_neox': 931, 'n_words': 184}