Sha256: b3c98ab6ed6e501d22909a00dfa22cc2d5f34edc8f2662d05c2ca3ae2d5db07f

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module ReadWriteConcernDocument

  class Spec

    attr_reader :description

    # Instantiate the new spec.
    #
    # @param [ String ] test_path The path to the file.
    #
    # @since 2.0.0
    def initialize(test_path)
      @spec = ::Utils.load_spec_yaml_file(test_path)
      @description = File.basename(test_path)
    end

    def tests
      @tests ||= @spec['tests'].collect do |spec|
        Test.new(spec)
      end
    end
  end

  class Test
    def initialize(spec)
      @spec = spec
      @description = @spec['description']
      @uri_string = @spec['uri']
    end

    attr_reader :description

    def valid?
      !!@spec['valid']
    end

    def input_document
      (@spec['readConcern'] || @spec['writeConcern']).tap do |concern|
        # Documented Ruby API matches the server API, and Ruby prohibits
        # journal key as used in the spec tests...
        if concern.key?('journal')
          concern['j'] = concern.delete('journal')
        end
        # ... and uses wtimeout instead of wtimeoutMS
        if concern.key?('wtimeoutMS')
          concern['wtimeout'] = concern.delete('wtimeoutMS')
        end
      end
    end

    def server_document
      @spec['readConcernDocument'] || @spec['writeConcernDocument']
    end

    # Returns true, false or nil
    def server_default?
      # Do not convert to boolean
      @spec['isServerDefault']
    end

    # Returns true, false or nil
    def acknowledged?
      # Do not convert to boolean
      @spec['isAcknowledged']
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/runners/read_write_concern_document.rb
mongo-2.17.4 spec/runners/read_write_concern_document.rb
mongo-2.18.3 spec/runners/read_write_concern_document.rb
mongo-2.18.2 spec/runners/read_write_concern_document.rb
mongo-2.17.3 spec/runners/read_write_concern_document.rb
mongo-2.18.1 spec/runners/read_write_concern_document.rb
mongo-2.18.0 spec/runners/read_write_concern_document.rb
mongo-2.17.2 spec/runners/read_write_concern_document.rb
mongo-2.16.3 spec/runners/read_write_concern_document.rb
mongo-2.18.0.beta1 spec/runners/read_write_concern_document.rb
mongo-2.16.2 spec/runners/read_write_concern_document.rb
mongo-2.17.1 spec/runners/read_write_concern_document.rb