123456789_123456789_123456789_123456789_123456789_

Module: Kernel

Relationships & Source Files
Defined in: lib/minitest/spec.rb

Overview

Kernel extensions for minitest

Instance Method Summary

Instance Method Details

describe(desc, *additional_desc, &block) (private)

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.

[ GitHub ]

  
# File 'lib/minitest/spec.rb', line 75

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