<commit_before>require 'hanitizer/generator'

module Hanitizer
  describe Generator::Context do
    subject(:context) { described_class.new row }

    let(:row) {
      {
        :first_name => 'Dynaguy'
      }
    }

    it 'has a row' do
      expect(context).to respond_to :row
    end

    describe '#apply_generator' do
      let(:name)  { 'address1' }
      let(:field) { 'street_address' }
      let(:value) { '1 Lost Lane' }
      let(:generator) {
        double('Generator::' + Inflector.pascalize(name), :generate => value)
      }

      before do
        context.apply_generator(generator, field)
      end

      it 'sets the named field' do
        expect(row[field]).to_not be_nil
      end

      it 'updates the named field' do
        expect(row[field]).to eq value
      end
    end

    describe '#execute' do
      let(:definition) {
        lambda {
          'HUNT'
        }
      }
      let(:field)  { :name }
      let(:result) { context.execute(&definition) }

      it 'binds the definition and executes it' do
        result = false

        test_context = context
        definition = lambda { |row|
          result = true if self.eql?(test_context)
        }

        expect {
          context.execute(&definition)
        }.to change { result }.from(false).to(true)
      end

      it 'passes the row when executing the definition' do
        row_passed = false
        definition = lambda { |incoming_row|
          row_passed = true if incoming_row.eql?(row)
        }

        expect {
          context.execute(&definition)
        }.to change { row_passed }.from(false).to(true)
      end

      it 'returns the row' do
        expect(context.execute(&definition)).to equal row
      end

      shared_examples_for 'a basic generator' do |field,value|
        raise ArgumentError, 'Block requires both field and value parameters' unless value

        let(:definition) {
          lambda { |row|
            send(field, field)
          }
        }

        let(:row) {
          {
            :first_name => 'Dynaguy',
            field => value
          }
        }

        let(:constant) { Generator.klass_for(field) }

        let("row_with_#{field}".to_sym) { row }
        let(:result) { sanitizer.sanitize(send "row_with_#{field}".to_sym) }

        display_name = field.to_s.gsub('_', ' ')

        it "creates a #{display_name} generator" do
          expect(constant).to receive(:new).and_call_original
          result
        end
      end

      shared_examples_for 'creating the correct generator' do
        it 'creates the correct generator' do
          expect(klass).to receive(:new).and_call_original
          context.execute(&definition)
        end<commit_msg>Removed unused shared examples<commit_after>require 'hanitizer/generator'

module Hanitizer
  describe Generator::Context do
    subject(:context) { described_class.new row }

    let(:row) {
      {
        :first_name => 'Dynaguy'
      }
    }

    it 'has a row' do
      expect(context).to respond_to :row
    end

    describe '#apply_generator' do
      let(:name)  { 'address1' }
      let(:field) { 'street_address' }
      let(:value) { '1 Lost Lane' }
      let(:generator) {
        double('Generator::' + Inflector.pascalize(name), :generate => value)
      }

      before do
        context.apply_generator(generator, field)
      end

      it 'sets the named field' do
        expect(row[field]).to_not be_nil
      end

      it 'updates the named field' do
        expect(row[field]).to eq value
      end
    end

    describe '#execute' do
      let(:definition) {
        lambda {
          'HUNT'
        }
      }
      let(:field)  { :name }
      let(:result) { context.execute(&definition) }

      it 'binds the definition and executes it' do
        result = false

        test_context = context
        definition = lambda { |row|
          result = true if self.eql?(test_context)
        }

        expect {
          context.execute(&definition)
        }.to change { result }.from(false).to(true)
      end

      it 'passes the row when executing the definition' do
        row_passed = false
        definition = lambda { |incoming_row|
          row_passed = true if incoming_row.eql?(row)
        }

        expect {
          context.execute(&definition)
        }.to change { row_passed }.from(false).to(true)
      end

      it 'returns the row' do
        expect(context.execute(&definition)).to equal row
      end

      shared_examples_for 'creating the correct generator' do
        it 'creates the correct generator' do
          expect(klass).to receive(:new).and_call_original
          context.execute(&definition)
        end
{'fraction_non_alphanumeric': 0.10435706695005313, 'fraction_numerical': 0.0008501594048884166, 'mean_word_length': 1.9765970904490828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '753042', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1348, 'n_words': 347}