Sha256: d2c39829ed3ee6e0fb4f61441f1f9999dfd418a506eb09aee2ce62259879948f

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require_relative './operators/eq'
require_relative './operators/ne'
require_relative './operators/in'
require_relative './operators/nin'

(WCC::Contentful::Store::Query::Interface::OPERATORS -
  %i[eq ne in nin]).each do |op|
    RSpec.shared_examples "supports :#{op} operator" do
      it 'TODO'
    end
  end

RSpec.shared_examples 'operators' do |feature_set|
  supported_operators =
    if feature_set.nil?
      WCC::Contentful::Store::Query::Interface::OPERATORS
        .each_with_object({}) { |k, h| h[k] = 'pending' }
    elsif feature_set.is_a?(Array)
      WCC::Contentful::Store::Query::Interface::OPERATORS
        .each_with_object({}) { |k, h| h[k] = feature_set.include?(k.to_sym) }
    elsif feature_s.is_a?(Hash)
      feature_set
    else
      raise ArgumentError, 'Please provide a hash or array of operators to test'
    end

  supported_operators.each do |op, value|
    next if value

    it "does not support :#{op}" do
      expect {
        subject.find_all(content_type: 'test')
          .apply('name' => { op => 'test' })
          .to_a
      }.to raise_error do |ex|
        expect(ex.to_s).to match(/not supported/)
      end
    end
  end

  supported_operators.each do |op, value|
    next unless value

    it_behaves_like "supports :#{op} operator" do
      before { pending(":#{op} operator to be implemented") } if value == 'pending'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wcc-contentful-1.2.0 lib/wcc/contentful/store/rspec_examples/operators.rb
wcc-contentful-1.1.2 lib/wcc/contentful/store/rspec_examples/operators.rb
wcc-contentful-1.1.1 lib/wcc/contentful/store/rspec_examples/operators.rb