Module: Cuprum::Collections::RSpec::Contracts::QueryContracts::ShouldPerformQueriesContract

Extended by:
RSpec::SleepingKingStudios::Contract
Defined in:
lib/cuprum/collections/rspec/contracts/query_contracts.rb

Overview

Contract validating the behavior when performing queries.

Instance Method Summary collapse

Instance Method Details

#apply(example_group, block: , operators: ) ⇒ Object

Adds the contract to the example group.

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    the example group to which the contract is applied.

  • block (Proc) (defaults to: )

    the expectations for each query context.

  • operators (Array<Symbol>) (defaults to: )

    the expected operators.



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
# File 'lib/cuprum/collections/rspec/contracts/query_contracts.rb', line 790

contract do |block:, operators: OPERATORS.values|
  operators = Set.new(operators.map(&:to_sym))

  wrap_context 'when the query has limit: value' do
    instance_exec(&block)
  end

  wrap_context 'when the query has offset: value' do
    instance_exec(&block)
  end

  wrap_context 'when the query has order: a simple ordering' do
    instance_exec(&block)
  end

  wrap_context 'when the query has order: a complex ordering' do
    instance_exec(&block)
  end

  context 'when the query has where: a block filter' do
    context 'with a simple filter' do
      include_context 'when the query has where: a simple block filter'

      instance_exec(&block)
    end

    context 'with a complex filter' do
      include_context 'when the query has where: a complex block filter'

      if operators.include?(OPERATORS::EQUAL) &&
         operators.include?(OPERATORS::NOT_EQUAL)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with an equals filter' do
      include_context 'when the query has where: an equal block filter'

      if operators.include?(OPERATORS::EQUAL)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a greater_than filter' do
      include_context 'when the query has where: a greater_than filter'

      if operators.include?(OPERATORS::GREATER_THAN)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a greater_than_or_equal_to filter' do
      include_context \
        'when the query has where: a greater_than_or_equal_to filter'

      if operators.include?(OPERATORS::GREATER_THAN_OR_EQUAL_TO)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a less_than filter' do
      include_context 'when the query has where: a less_than filter'

      if operators.include?(OPERATORS::LESS_THAN)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a less_than_or_equal_to filter' do
      include_context \
        'when the query has where: a less_than_or_equal_to filter'

      if operators.include?(OPERATORS::LESS_THAN_OR_EQUAL_TO)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a not_equal filter' do
      include_context 'when the query has where: a not_equal block filter'

      if operators.include?(OPERATORS::NOT_EQUAL)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a not_one_of filter' do
      include_context \
        'when the query has where: a not_one_of block filter'

      if operators.include?(OPERATORS::NOT_ONE_OF)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end

    context 'with a one_of filter' do
      include_context 'when the query has where: a one_of block filter'

      if operators.include?(OPERATORS::ONE_OF)
        instance_exec(&block)
      else
        # :nocov:
        pending
        # :nocov:
      end
    end
  end

  wrap_context 'when the query has multiple query options' do
    instance_exec(&block)
  end
end