<commit_before>require 'spec_helper'

module Crichton
  module Descriptor
    describe SemanticDecorator do
      let(:parent_descriptor) do
        descriptor = mock('parent_descriptor')
        descriptor.stub(:child_descriptor_document).with('drds').and_return(@descriptor_document)
        descriptor
      end
      let(:descriptor) { Detail.new(mock('resource_descriptor'), parent_descriptor, 'drds') }
      let(:decorator) { SemanticDecorator.new(@target, descriptor) }
      
      describe '#source_defined?' do
        context 'with hash target' do
          it 'returns true if the hash includes the descriptor value' do
            @descriptor_document = {'name' => 'uuid'}
            value = mock('value')
            @target = {'uuid' => value}
            decorator.source_defined?.should be_true
          end

          it 'returns false if the hash does not include the descriptor value' do
            @descriptor_document = {'name' => 'uuid'}
            @target = {}
            decorator.source_defined?.should be_false
          end
        end

        context 'with object target' do
          it 'returns true if the object exposes the descriptor value' do
            @descriptor_document = {'source' => 'uuid'}
            value = mock('value')
            @target = Class.new do
              self.class.define_method(:uuid) { value }
            end
            decorator.should be_present
          end

          it 'returns false if the object does not expose the descriptor value' do
            @descriptor_document = {'source' => 'uuid'}
            @target = Class.new
            decorator.should be_present
          end
        end
      end
      
      describe '#value' do
        context 'with hash target' do
          it 'returns the value of the associated attribute of the hash' do
            @descriptor_document = {'name' => 'uuid' }
            value = mock('value')
            @target = {'uuid' => value}
            decorator.value.should == value
          end
        end
        
        context 'with object target' do
          it 'returns the value of the attribute of the object' do
            @descriptor_document = {'source' => 'uuid'}
            value = mock('value')
            @target = Class.new do 
              self.class.define_method('uuid') { value }
            end
            decorator.value.should == value
          end
        end
      end
    end
  end
end<commit_msg>Added logger spec<commit_after>require 'spec_helper'

module Crichton
  module Descriptor
    describe SemanticDecorator do
      let(:parent_descriptor) do
        descriptor = mock('parent_descriptor')
        descriptor.stub(:child_descriptor_document).with('drds').and_return(@descriptor_document)
        descriptor
      end
      let(:descriptor) { Detail.new(mock('resource_descriptor'), parent_descriptor, 'drds') }
      let(:decorator) { SemanticDecorator.new(@target, descriptor) }
      
      describe '#source_defined?' do
        context 'with hash target' do
          it 'returns true if the hash includes the descriptor value' do
            @descriptor_document = {'name' => 'uuid'}
            value = mock('value')
            @target = {'uuid' => value}
            decorator.source_defined?.should be_true
          end

          it 'returns false if the hash does not include the descriptor value' do
            @descriptor_document = {'name' => 'uuid'}
            @target = {}
            decorator.source_defined?.should be_false
          end
        end

        context 'with object target' do
          it 'returns true if the object exposes the descriptor value' do
            @descriptor_document = {'source' => 'uuid'}
            value = mock('value')
            @target = Class.new do
              self.class.define_method(:uuid) { value }
            end
            decorator.should be_present
          end

          it 'returns false if the object does not expose the descriptor value' do
            @descriptor_document = {'source' => 'uuid'}
            @target = Class.new
            decorator.should be_present
          end
        end
      end
      
      describe '#value' do
        context 'with hash target' do
          it 'returns the value of the associated attribute of the hash' do
            @descriptor_document = {'name' => 'uuid' }
            value = mock('value')
            @target = {'uuid' => value}
            decorator.value.should == value
          end
        end
        
        context 'with object target' do
          it 'returns the value of the attribute of the object' do
            @descriptor_document = {'source' => 'uuid'}
            value = mock('value')
            @target = Class.new do 
              self.class.define_method('uuid') { value }
            end
            decorator.value.should == value
          end
        end

        context 'with object target' do
          it 'returns the value of the attribute of the object' do
            @descriptor_document = {'source' => 'uuid'}
            @target = nil
            @logger = mock(:logger)
            @logger.should_receive(:warn)
            Crichton.should_receive(:logger).once.and_return(@logger)
            decorator.value
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08933283075763288, 'fraction_numerical': 0.0, 'mean_word_length': 1.8273841236014918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '6739884', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1300, 'n_words': 417}