Where is the have_fields RSpec matcher defined?

拈花ヽ惹草 提交于 2020-01-05 05:45:07

问题


A recent question on using rspec featured some code with a have_fields matcher in it.

A search indicated that have_fields was referenced in the mongoid-rspec gem, but when I went to GitHub, I could only find it referenced in the spec files.

Similar searches of RSpec core and related gems came up empty as well.


回答1:


You might be looking for the mongoid-minitest gem.

In have_field.rb it declares have_fields as an alias:

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)


来源:https://stackoverflow.com/questions/18152278/where-is-the-have-fields-rspec-matcher-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!