Sha256: 28174d968dcf54a785f5e986bb1a4bcab678e37aeaefb2dc65ca4bc0eacfe20a

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

module Mongo
  module CRUD
    # Represents a CRUD specification test.
    class Spec

      # Instantiate the new spec.
      #
      # @example Create the spec.
      #   Spec.new(file)
      #
      # @param [ String ] file The name of the file.
      #
      # @since 2.0.0
      def initialize(file)
        contents = ERB.new(File.read(file)).result

        # Since Ruby driver binds a client to a database, change the
        # database name in the spec to the one we are using
        contents.sub!(/"retryable-reads-tests"/, '"ruby-driver"')
        contents.sub!(/"transaction-tests"/, '"ruby-driver"')
        contents.sub!(/"withTransaction-tests"/, '"ruby-driver"')

        @spec = YAML.load(ERB.new(contents).result)
        @description = File.basename(file)
        @data = @spec['data']
        @tests = @spec['tests']

        @requirements = if run_on = @spec['runOn']
          run_on.map do |spec|
            Requirement.new(spec)
          end
        elsif Requirement::YAML_KEYS.any? { |key| @spec.key?(key) }
          [Requirement.new(@spec)]
        else
          nil
        end
      end

      # @return [ String ] description The spec description.
      #
      # @since 2.0.0
      attr_reader :description

      attr_reader :requirements

      def collection_name
        # Older spec tests do not specify a collection name, thus
        # we provide a default here
        @spec['collection_name'] || 'crud_spec_test'
      end

      def bucket_name
        @spec['bucket_name']
      end

      def database_name
        @spec['database_name']
      end

      # Get a list of Test instances, one for each test definition.
      def tests
        @tests.map do |test|
          Mongo::CRUD::CRUDTest.new(@data, test)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongo-2.9.2 spec/support/crud/spec.rb
mongo-2.9.1 spec/support/crud/spec.rb
mongo-2.9.1.rc0 spec/support/crud/spec.rb
mongo-2.9.0 spec/support/crud/spec.rb
mongo-2.9.0.rc1 spec/support/crud/spec.rb
mongo-2.9.0.rc0 spec/support/crud/spec.rb