<commit_before># encoding: utf-8

require 'spec_helper'

describe Relation::Header, '.coerce' do
  let(:object) { described_class                             }
  let(:header) { object.new([ Attribute::Integer.new(:id) ]) }
  let(:array)  { [ [ :id, Integer ] ]                        }

  context 'with a block' do
    subject { object.coerce(argument, &block) }

    context 'when the argument is a Header' do
      let(:argument) { header                            }
      let(:block)    { proc { raise 'should not raise' } }

      it { should equal(header) }
    end

    context 'when the argument responds to #to_ary' do
      let(:argument) { array }

      context 'and the block returns another attribute' do
        let(:block) { lambda { |attribute| other } }
        let(:other) { Attribute::Object.new(:id)   }

        it { should be_instance_of(object) }

        it { should eql(object.new([ other ])) }
      end

      context 'and the block does not match another attribute' do
        let(:block) { lambda { |attribute| nil } }

        it { should be_instance_of(object) }

        it { should eql(header) }
      end
    end

    context 'when the argument is not a Header and does not respond to #to_ary' do
      let(:argument) { Object.new                 }
      let(:block)    { lambda { |attribute| nil } }

      specify { expect { subject }.to raise_error(NoMethodError) }
    end
  end

  context 'without a block' do
    subject { object.coerce(argument) }

    context 'when the argument is a Header' do
      let(:argument) { header }

      it { should equal(header) }
    end

    context 'when the argument responds to #to_ary' do
      let(:argument) { array }

      it { should be_instance_of(object) }

      it { should eql(header) }
    end

    context 'when the argument is not a Header and does not respond to #to_ary' do
      let(:argument) { Object.new }

      specify { expect { subject }.to raise_error(NoMethodError) }
    end
  end
end
<commit_msg>Fix Header.coerce spec to kill mutations<commit_after># encoding: utf-8

require 'spec_helper'

describe Relation::Header, '.coerce' do
  let(:object)    { described_class             }
  let(:header)    { object.new([ attribute ])   }
  let(:attribute) { Attribute::Integer.new(:id) }
  let(:array)     { [ [ :id, Integer ] ]        }

  context 'with a block' do
    subject { object.coerce(argument, &block) }

    context 'when the argument is a Header' do
      let(:argument) { header                            }
      let(:block)    { proc { raise 'should not raise' } }

      it { should equal(header) }
    end

    context 'when the argument responds to #to_ary' do
      let(:argument) { array }

      context 'and the block returns another attribute' do
        let(:block) { lambda { |attribute| other } }
        let(:other) { Attribute::Object.new(:id)   }

        it { should be_instance_of(object) }

        it { should eql(object.new([ other ])) }

        its(:keys) { should be_empty }
      end

      context 'and the block does not match another attribute' do
        let(:block) { lambda { |attribute| nil } }

        it { should be_instance_of(object) }

        it { should eql(header) }

        its(:keys) { should be_empty }
      end
    end

    context 'when the argument is not a Header and does not respond to #to_ary' do
      let(:argument) { Object.new                 }
      let(:block)    { lambda { |attribute| nil } }

      specify { expect { subject }.to raise_error(NoMethodError) }
    end
  end

  context 'without a block' do
    subject { object.coerce(argument) }

    context 'when the argument is a Header' do
      let(:argument) { header }

      it { should equal(header) }
    end

    context 'when the argument responds to #to_ary' do
      let(:argument) { array }

      it { should be_instance_of(object) }

      it { should eql(header) }

      its(:keys) { should be_empty }
    end

    context 'when the argument is not a Header and does not respond to #to_ary' do
      let(:argument) { Object.new }

      specify { expect { subject }.to raise_error(NoMethodError) }
    end
  end

  context 'with an attribute' do
    subject { object.coerce(attribute) }

    it { should be_instance_of(object) }

    its(:to_a) { should == [ attribute ] }

    its(:keys) { should be_empty }
  end

  context 'with options' do
    subject { object.coerce(array, options) }

    let(:options) { { :keys => [ array ] } }

    it { should be_instance_of(object) }

    its(:to_a) { should == array }

    its(:keys) { should == [ array ] }
  end
end

{'fraction_non_alphanumeric': 0.11062906724511931, 'fraction_numerical': 0.0004338394793926247, 'mean_word_length': 2.2655807365439093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5394936', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1345, 'n_words': 433}