<commit_before>require 'spec_helper'

module Dbd
  describe Context do

    let(:context) { described_class.new }
    let(:context_subject) { context.subject }

    describe '.new' do
      describe 'without a subject argument' do
        it 'has created a new subject' do
          context.subject.should be_a(described_class.new_subject.class)
        end
      end

      describe 'with a subject argument' do
        it 'has stored the resource_subject' do
          described_class.new(subject: context_subject).subject.
            should == context_subject
        end
      end

      describe 'with a context_subject argument' do
        it 'raises an ContextError' do
          lambda{ described_class.new(context_subject: context_subject) }.
            should raise_error(ArgumentError)
        end
      end
    end

    describe 'context_subject' do
      it 'raises NoMethodError when called' do
        lambda{ context.context_subject }.should raise_error(NoMethodError)
      end
    end

    describe 'TestFactories::Context' do
      it '.context works' do
        TestFactories::Context.context
      end
    end

    describe 'the collection' do

      let(:context_fact_visibility) { TestFactories::ContextFact.visibility } # nil subject
      let(:context_visibility_with_incorrect_subject) { TestFactories::ContextFact.visibility(TestFactories::ContextFact.new_subject) }
      let(:context_visibility_with_correct_subject) { TestFactories::ContextFact.visibility(context_subject) }

      describe 'adding context_facts with << ' do
        it 'with correct subject it works' do
          context << context_visibility_with_correct_subject
          context.first.subject.should == context_subject
        end

        it 'with incorrect subject it raises SetOnceError' do
          lambda{ context << context_visibility_with_incorrect_subject }.
            should raise_error(RubyPeterV::SetOnceError),
              "Value of subject was #{context_visibility_with_incorrect_subject.subject}, " \
              "trying to set it to #{context.subject}"
        end

        it 'with nil subject it sets the subject' do
          context << context_fact_visibility
          context.first.subject.should == context_subject
        end

        it 'with nil (=correct) context_subject it is a noop' do
          context << context_fact_visibility
          context.first.context_subject.should be_nil
        end
      end<commit_msg>Add pending test for Context#<<[context_fact]<commit_after>require 'spec_helper'

module Dbd
  describe Context do

    let(:context) { described_class.new }
    let(:context_subject) { context.subject }

    describe '.new' do
      describe 'without a subject argument' do
        it 'has created a new subject' do
          context.subject.should be_a(described_class.new_subject.class)
        end
      end

      describe 'with a subject argument' do
        it 'has stored the resource_subject' do
          described_class.new(subject: context_subject).subject.
            should == context_subject
        end
      end

      describe 'with a context_subject argument' do
        it 'raises an ContextError' do
          lambda{ described_class.new(context_subject: context_subject) }.
            should raise_error(ArgumentError)
        end
      end
    end

    describe 'context_subject' do
      it 'raises NoMethodError when called' do
        lambda{ context.context_subject }.should raise_error(NoMethodError)
      end
    end

    describe 'TestFactories::Context' do
      it '.context works' do
        TestFactories::Context.context
      end
    end

    describe 'the collection' do

      let(:context_fact_visibility) { TestFactories::ContextFact.visibility } # nil subject
      let(:context_visibility_with_incorrect_subject) { TestFactories::ContextFact.visibility(TestFactories::ContextFact.new_subject) }
      let(:context_visibility_with_correct_subject) { TestFactories::ContextFact.visibility(context_subject) }

      describe 'adding context_facts with << ' do
        it 'with correct subject it works' do
          context << context_visibility_with_correct_subject
          context.first.subject.should == context_subject
        end

        it 'works with an array of contexts_facts' do
          pending "TODO"
          # NOTE: also use it in dbd_onto meta_context file
          context << [context_visibility_with_correct_subject]
          context.first.subject.should == context_subject
        end

        it 'with incorrect subject it raises SetOnceError' do
          lambda{ context << context_visibility_with_incorrect_subject }.
            should raise_error(RubyPeterV::SetOnceError),
              "Value of subject was #{context_visibility_with_incorrect_subject.subject}, " \
              "trying to set it to #{context.subject}"
        end

        it 'with nil subject it sets the subject' do
          context << context_fact_visibility
          context.first.subject.should == context_subject
        end

        it 'with nil (=correct) context_subject it is a noop' do
          context << context_fact_visibility
          context.first.context_subject.should be_nil
        end
      end
{'fraction_non_alphanumeric': 0.06780310285385942, 'fraction_numerical': 0.0, 'mean_word_length': 2.669711876317639, 'pattern_counts': {'":': 0, '<': 27, '<?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': '6184720', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1329, 'n_words': 380}