<commit_before>require File.expand_path('../../spec_helper', __FILE__)

describe Luggage::Validator do
  subject { Luggage::Validator }

  #
  # initialize
  #

  describe '#initialize' do
    describe 'scenarios' do
      it 'should be [:default] when no scenarios option is given' do
        Luggage::Validator.new(nil, nil).scenarios.should == [:default]
      end

      it 'should be [:scenario] when the scenarios option is [:scenario]' do
        validator = Luggage::Validator.new(nil, nil, :scenarios => [:scenario])
        validator.scenarios.should == [:scenario]
      end

      it 'should be [:scenario] when the scenarios option is :scenario' do
        validator = Luggage::Validator.new(nil, nil, :scenarios => :scenario)
        validator.scenarios.should == [:scenario]
      end
    end
  end

  #
  # context
  #

  it { should have_public_method_defined(:context) }

  describe '#context' do
    before(:all) do
      @context = Luggage::Validator.new('context', 'matcher').context
    end

    it 'should return the context' do
      @context.should == 'context'
    end
  end

  #
  # matcher
  #

  it { should have_public_method_defined(:matcher) }

  describe '#matcher' do
    before(:all) do
      @matcher = Luggage::Validator.new('context', 'matcher').matcher
    end

    it 'should return the matcher' do
      @matcher.should == 'matcher'
    end
  end

  #
  # validate
  #

  it { should have_public_method_defined(:validate) }

  describe '#validate' do
    describe 'when the validator is positive' do
      before(:all) do
        @validator = Luggage::Validator.new(Luggage::Context.new(:name),
          Luggage::Matchers::Nil.new, :negative => false)
      end

      describe 'when the matcher passes' do
        it 'should return true' do
          @validator.validate(mock(:name => nil)).should be_true
        end
      end

      describe 'when the matcher fails' do
        before(:all) do
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end

        # Perhaps this is one for Cucumber?
        it 'should add the error to the record errors'
      end

      describe 'when the matcher fails and return an error' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return([false, :error])
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end

        # Perhaps this is one for Cucumber?
        it 'should add the error to the record errors'
      end

      # Rubinius.
      describe 'when the matcher returns a non-array which responds to #to_a' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return(mock(:to_a => []))
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end

        it 'should return Array[..., nil]' do
          @result[1].should be_nil
        end
      end
    end # when the matcher is positive

    describe 'when the validator is negative' do
      before(:all) do
        @validator = Luggage::Validator.new(Luggage::Context.new(:name),
          Luggage::Matchers::Nil.new, :negative => true)
      end

      describe 'when the matcher passes' do
        it 'should return Array[false, ...]' do
          @validator.validate(mock(:name => nil)).first.should be_false
        end
      end

      describe 'when the matcher fails' do
        before(:all) do
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end

        # Perhaps this is one for Cucumber?
        it 'should add the error to the record errors'
      end

      describe 'when the matcher fails and return an error' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return([false, :error])
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end

        # Perhaps this is one for Cucumber?
        it 'should add the error to the record errors'
      end

      # Rubinius.
      describe 'when the matcher returns a non-array which responds to #to_a' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return(mock(:to_a => []))
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end

        it 'should return Array[..., an_error]' do
          @result[1].should_not be_nil
        end
      end
    end # when the matcher is negative

    #
    # argument counts
    #

    describe 'when matcher #matches? accepts' do
      describe 'one argument' do
        it 'should supply the attribute' do
          value  = ''
<commit_msg>Remove pending specs which are tested in features.<commit_after>require File.expand_path('../../spec_helper', __FILE__)

describe Luggage::Validator do
  subject { Luggage::Validator }

  #
  # initialize
  #

  describe '#initialize' do
    describe 'scenarios' do
      it 'should be [:default] when no scenarios option is given' do
        Luggage::Validator.new(nil, nil).scenarios.should == [:default]
      end

      it 'should be [:scenario] when the scenarios option is [:scenario]' do
        validator = Luggage::Validator.new(nil, nil, :scenarios => [:scenario])
        validator.scenarios.should == [:scenario]
      end

      it 'should be [:scenario] when the scenarios option is :scenario' do
        validator = Luggage::Validator.new(nil, nil, :scenarios => :scenario)
        validator.scenarios.should == [:scenario]
      end
    end
  end

  #
  # context
  #

  it { should have_public_method_defined(:context) }

  describe '#context' do
    before(:all) do
      @context = Luggage::Validator.new('context', 'matcher').context
    end

    it 'should return the context' do
      @context.should == 'context'
    end
  end

  #
  # matcher
  #

  it { should have_public_method_defined(:matcher) }

  describe '#matcher' do
    before(:all) do
      @matcher = Luggage::Validator.new('context', 'matcher').matcher
    end

    it 'should return the matcher' do
      @matcher.should == 'matcher'
    end
  end

  #
  # validate
  #

  it { should have_public_method_defined(:validate) }

  describe '#validate' do
    describe 'when the validator is positive' do
      before(:all) do
        @validator = Luggage::Validator.new(Luggage::Context.new(:name),
          Luggage::Matchers::Nil.new, :negative => false)
      end

      describe 'when the matcher passes' do
        it 'should return true' do
          @validator.validate(mock(:name => nil)).should be_true
        end
      end

      describe 'when the matcher fails' do
        before(:all) do
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end
      end

      describe 'when the matcher fails and return an error' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return([false, :error])
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end
      end

      # Rubinius.
      describe 'when the matcher returns a non-array which responds to #to_a' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return(mock(:to_a => []))
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end

        it 'should return Array[..., nil]' do
          @result[1].should be_nil
        end
      end
    end # when the matcher is positive

    describe 'when the validator is negative' do
      before(:all) do
        @validator = Luggage::Validator.new(Luggage::Context.new(:name),
          Luggage::Matchers::Nil.new, :negative => true)
      end

      describe 'when the matcher passes' do
        it 'should return Array[false, ...]' do
          @validator.validate(mock(:name => nil)).first.should be_false
        end
      end

      describe 'when the matcher fails' do
        before(:all) do
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end
      end

      describe 'when the matcher fails and return an error' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return([false, :error])
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[true, ...]' do
          @result.first.should be_true
        end
      end

      # Rubinius.
      describe 'when the matcher returns a non-array which responds to #to_a' do
        before(:all) do
          @validator.matcher.stub(:matches?).and_return(mock(:to_a => []))
          @result = @validator.validate(mock(:name => ''))
        end

        it 'should return Array[false, ...]' do
          @result.first.should be_false
        end

        it 'should return Array[..., an_error]' do
          @result[1].should_not be_nil
        end
      end
    end # when the matcher is negative

    #
    # argument counts
    #

    describe 'when matcher #matches? accepts' do
      describe 'one argument' do
        it 'should supply the attribute' do
          value  = ''

{'fraction_non_alphanumeric': 0.11537284504743446, 'fraction_numerical': 0.0004080383556054269, 'mean_word_length': 2.213372664700098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '5501079', 'n_tokens_mistral': 2917, 'n_tokens_neox': 2829, 'n_words': 831}