In Files

  • minitest-5.15.0/lib/minitest/spec.rb

Methods

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.15.0/lib/minitest/spec.rb, line 76
def describe desc, *additional_desc, &block # :doc:
  stack = Minitest::Spec.describe_stack
  name  = [stack.last, desc, *additional_desc].compact.join("::")
  sclas = stack.last || if Class === self && kind_of?(Minitest::Spec::DSL) then
                          self
                        else
                          Minitest::Spec.spec_type desc, *additional_desc
                        end

  cls = sclas.create name, desc

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