哪里have_fields RSpec的匹配定义?(Where is the have_fields

2019-10-18 11:07发布

一个使用RSpec的最近的问题与一个有特色的一些代码have_fields它匹配。

一个搜索表明, have_fields在引用mongoid-rspec宝石,但是当我到了GitHub上,我只能找到它在规范文件中引用。

RSpec的核心和相关的宝石搜索同类产品来到了空为好。

Answer 1:

你可能会寻找mongoid-MINITEST宝石。

在have_field.rb它声明have_fields作为别名:

module Mongoid
  module Matchers
    module Document
      # TODO: Add documentation.
      def have_field *fields
        HaveFieldMatcher.new(*fields)
      end
      alias :have_fields :have_field

      private

      class HaveFieldMatcher < Matcher
        attr_reader :fields, :klass, :type, :default, :errors

        def initialize *fields
          @fields = fields.collect(&:to_s)
          @errors = []
        end

        def of_type type
          @type = type
          self
        end

        ... (rest of file omitted)


文章来源: Where is the have_fields RSpec matcher defined?