<commit_before>require 'spec_helper'
require 'sequel'

describe "SQLite Source" do
  context "#initialize" do

    context "when missing parameter" do
      it { expect { Sqlite.new }.to raise_error }
      it { expect { Sqlite.new(['col1', 'col2'], 'path_to_db') }.to raise_error }
      it { expect { Sqlite.new(['col1', 'col2'], 'path_to_db', nil) }.to raise_error('columns, db_path and query are required') }
      it { expect { Sqlite.new(nil, 'path_to_db', '12321') }.to raise_error('columns, db_path and query are required') }
      it { expect { Sqlite.new(['col1', 'col2'], nil, '12321') }.to raise_error('columns, db_path and query are required') }
    end

    context "when parameters correctly" do
      it 'should created instance' do 
        sqlite = Sqlite.new(['col1', 'col2'], 'database.db', 'select * from table')
        expect(sqlite.columns).to eq(['col1', 'col2'])
      end
    end

    context 'instantiate with sources.yml file' do

      let(:config) { OptimusPrime::Config.new(file_path: "spec/supports/sources.yml") }
      let(:sqlite_attributes) { config.get_source_by_id('sqlite3_game_level_database') }

      it 'should created instance' do
        sqlite_object = Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query'])
        expect(sqlite_object.columns).to eq(sqlite_attributes['columns'])
        expect(sqlite_object.query).to eq(sqlite_attributes['query'])
      end

    end
    
  end

  context "#retrieve_data" do

    context "configuration correct" do
      let(:config) { OptimusPrime::Config.new(file_path: "spec/supports/sources.yml") }
      let(:sqlite_attributes) { config.get_source_by_id('sqlite3_game_level_database') }
      let(:sqlite_object) { Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query']) }

      it 'should return array data' do
        expected_data = [1, 'dragon_cube', 50]
        expect(sqlite_object.retrieve_data.first).to eq(expected_data)
      end
    end

    context "query incorrect" do
      let(:config) { OptimusPrime::Config.new(file_path: "spec/supports/sources.yml") }
      let(:sqlite_attributes) { config.get_source_by_id('game_level_db_incorrect') }
      let(:sqlite_object) { Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query']) }

      it 'should error' do
        expect { sqlite_object.retrieve_data }.to raise_error
      end
    end
  end
end<commit_msg>moved config on top of file<commit_after>require 'spec_helper'
require 'sequel'

describe "SQLite Source" do
  context "#initialize" do

    context "when missing parameter" do
      it { expect { Sqlite.new }.to raise_error }
      it { expect { Sqlite.new(['col1', 'col2'], 'path_to_db') }.to raise_error }
      it { expect { Sqlite.new(['col1', 'col2'], 'path_to_db', nil) }.to raise_error('columns, db_path and query are required') }
      it { expect { Sqlite.new(nil, 'path_to_db', '12321') }.to raise_error('columns, db_path and query are required') }
      it { expect { Sqlite.new(['col1', 'col2'], nil, '12321') }.to raise_error('columns, db_path and query are required') }
    end

    context "when parameters correctly" do
      it 'should created instance' do 
        sqlite = Sqlite.new(['col1', 'col2'], 'database.db', 'select * from table')
        expect(sqlite.columns).to eq(['col1', 'col2'])
      end
    end

    context 'instantiate with sources.yml file' do

      let(:config) { OptimusPrime::Config.new(file_path: "spec/supports/sources.yml") }
      let(:sqlite_attributes) { config.get_source_by_id('sqlite3_game_level_database') }

      it 'should created instance' do
        sqlite_object = Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query'])
        expect(sqlite_object.columns).to eq(sqlite_attributes['columns'])
        expect(sqlite_object.query).to eq(sqlite_attributes['query'])
      end

    end
    
  end

  context "#retrieve_data" do

    let(:config) { OptimusPrime::Config.new(file_path: "spec/supports/sources.yml") }

    context "configuration correct" do
      let(:sqlite_attributes) { config.get_source_by_id('sqlite3_game_level_database') }
      let(:sqlite_object) { Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query']) }

      it 'should return array data' do
        expected_data = [1, 'dragon_cube', 50]
        expect(sqlite_object.retrieve_data.first).to eq(expected_data)
      end
    end

    context "query incorrect" do
      let(:sqlite_attributes) { config.get_source_by_id('game_level_db_incorrect') }
      let(:sqlite_object) { Sqlite.new(sqlite_attributes['columns'], sqlite_attributes['file_path'], sqlite_attributes['query']) }

      it 'should error' do
        expect { sqlite_object.retrieve_data }.to raise_error
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1329538524090262, 'fraction_numerical': 0.010164667615368977, 'mean_word_length': 3.929859719438878, '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': '3008730', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1540, 'n_words': 343}