class Minitest::Spec::SharedDescription::DSL

Attributes

shared_descriptions[R]

An array of arguments and blocks to pass to describe for classes that include the current module.

Public Instance Methods

describe(*desc, &block) click to toggle source

Add a describe block that will be shared by all classes including the current module. Example:

EmptyBehavior = shared_description do
  describe "empty" do
    before do
      @that = double
    end

    it "must be empty?" do
      @that.must_be :empty?
    end

    it "must have size equal to 0" do
      @that.size.must_equal 0
    end
  end
end

describe "array" do
  def double; @this + @this end

  before do
    @this = []
  end

  include EmptyBehavior
end

describe "hash" do
  def double; @this.merge(@this) end

  before do
    @this = {}
  end

  include EmptyBehavior
end
   # File lib/minitest/shared_description.rb
49 def describe(*desc, &block)
50   (@shared_descriptions ||= []) << [desc, block]
51 end
include(*mods) click to toggle source

If including another shared description module, copy the shared description class definition blocks into the receiver’s.

Calls superclass method
   # File lib/minitest/shared_description.rb
55 def include(*mods)
56   mods.each do |mod|
57     if mod.is_a?(DSL) && mod.shared_descriptions
58       (@shared_descriptions ||= []).concat(mod.shared_descriptions)
59     end
60   end
61   super
62 end