Sha256: 69e1a6c9f8f64f0a46d4632907f6cd1ffd7f5471a79a46e9f58ccad09cc0d336

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

# Remarkable core module
module Remarkable
  # A module that keeps all matchers added. This is useful because it allows
  # to include matchers in Test::Unit as well.
  module Matchers; end

  # Helper that includes required Remarkable modules into the given klass.
  #
  # If the module to be included responds to :after_include, it's called with the
  # target as argument.
  #
  def self.include_matchers!(base, target=nil)
    if target.nil?
      if rspec_defined?
        target = Spec::Example::ExampleGroup
      else
        raise ArgumentError, "You haven't supplied the target to include_matchers! and RSpec is not loaded, so we cannot infer one."
      end
    end

    metaclass = (class << target; self; end)
    target.send :extend, Remarkable::Pending unless metaclass.ancestors.include?(Remarkable::Pending)
    target.send :extend, Remarkable::Macros  unless metaclass.ancestors.include?(Remarkable::Macros)

    if defined?(base::Matchers)
      target.send :include, base::Matchers

      Remarkable::Matchers.send :extend, base::Matchers
      Remarkable::Matchers.send :include, base::Matchers
    end

    if base.respond_to?(:after_include)
      base.after_include(target)
    end
  end

  def self.rspec_defined? #:nodoc:
    defined?(Spec)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
remarkable-3.1.7 lib/remarkable/matchers.rb
remarkable-3.1.8 lib/remarkable/matchers.rb
remarkable-3.1.4 lib/remarkable/matchers.rb
remarkable-3.1.5 lib/remarkable/matchers.rb
remarkable-3.1.6 lib/remarkable/matchers.rb