module Kernel

Kernel extensions for minitest

Private Instance Methods

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

Describe a series of expectations for a given target desc.

Defines a test class subclassing from either Minitest::Spec or from the surrounding describe’s class. The surrounding class may subclass Minitest::Spec manually in order to easily share code:

class MySpec < Minitest::Spec
  # ... shared code ...
end

class TestStuff < MySpec
  it "does stuff" do
    # shared code available here
  end
  describe "inner stuff" do
    it "still does stuff" do
      # ...and here
    end
  end
end

For more information on getting started with writing specs, see:

www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html

For some suggestions on how to improve your specs, try:

betterspecs.org

but do note that several items there are debatable or specific to rspec.

For more information about expectations, see Minitest::Expectations.

# File minitest-5.25.4/lib/minitest/spec.rb, line 82
def describe desc, *additional_desc, &block # :doc:
  stack = Minitest::Spec.describe_stack
  is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL)
  name  = [stack.last, desc, *additional_desc]
  name.prepend self if stack.empty? && is_spec_class
  sclas =
    stack.last                 \
    || (is_spec_class && self) \
    || Minitest::Spec.spec_type(desc, *additional_desc)

  cls = sclas.create name.compact.join("::"), desc

  stack.push cls
  cls.class_eval(&block)
  stack.pop
  cls
end