<commit_before>require 'spec_helper'
load File.expand_path('../../../../lib/tasks/import.thor', __FILE__)

RSpec.describe Import do
  let(:task) { Import::Start.new }

  describe '#importers' do
    context 'when provided with the default sources' do
      it 'returns X2 and STAR importers' do
        expect(task.importers(['x2', 'star'])).to eq([SomervilleX2Importers, SomervilleStarImporters])
      end
    end
    context 'when provided with a duplicated source' do
      it 'returns just one reference to the requested importer' do
        expect(task.importers(['x2', 'x2'])).to eq([SomervilleX2Importers])
      end
    end
    context 'when provided with invalid sources' do
      it 'returns an empty array' do
        expect(task.importers(['x3'])).to eq([])
      end
    end
  end

  describe '#load_rails' do
    it 'defines Rails' do
      expect(task).to receive(:require).with(/config\/environment.rb/)
      task.load_rails
    end
  end
<commit_msg>Test running import task end-to-end<commit_after>require 'spec_helper'
load File.expand_path('../../../../lib/tasks/import.thor', __FILE__)

RSpec.describe Import do
  let(:task) { Import::Start.new }

  describe '.start' do
    before do
      sftp_client_double = double(read_file: 'meow')
      allow(SftpClient).to receive_messages(for_x2: sftp_client_double, for_star: sftp_client_double)
    end

    let(:commands) { Import::Start.start }

    it 'invokes all the commands and returns the correct kind of values' do
      expect(commands[0]).to eq false
      expect(commands[1]).to eq nil
      expect(commands[2]).to eq ['HEA']
      expect(commands[3]).to be_a Array
      expect(commands[4]).to eq []
      expect(commands[5]).to eq nil
    end

    let(:importers) { commands[3] }

    it 'returns the correct importers' do
      expect(importers.size).to eq 2
      expect(importers[0]).to be_a Importer
      expect(importers[1]).to be_a Importer
    end

  end

  describe '#importers' do
    context 'when provided with the default sources' do
      it 'returns X2 and STAR importers' do
        expect(task.importers(['x2', 'star'])).to eq([SomervilleX2Importers, SomervilleStarImporters])
      end
    end
    context 'when provided with a duplicated source' do
      it 'returns just one reference to the requested importer' do
        expect(task.importers(['x2', 'x2'])).to eq([SomervilleX2Importers])
      end
    end
    context 'when provided with invalid sources' do
      it 'returns an empty array' do
        expect(task.importers(['x3'])).to eq([])
      end
    end
  end

  describe '#load_rails' do
    it 'defines Rails' do
      expect(task).to receive(:require).with(/config\/environment.rb/)
      task.load_rails
    end
  end

{'fraction_non_alphanumeric': 0.11919561243144425, 'fraction_numerical': 0.009140767824497258, 'mean_word_length': 3.0473372781065087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4125887', 'n_tokens_mistral': 875, 'n_tokens_neox': 830, 'n_words': 244}