SusSourceSusDescribe

module Describe

Represents a test group that describes a subject (class, module, or feature).

Definitions

attr_accessor :subject

Signature

attribute Object

The subject being described.

def self.build(parent, subject, unique: true, &block)

Build a new describe block class.

Signature

parameter parent Class

The parent context class.

parameter subject Object

The subject to describe.

parameter unique Boolean

Whether the identity should be unique.

yields {...}

Optional block containing nested tests.

returns Class

A new describe block class.

Implementation

def self.build(parent, subject, unique: true, &block)
	base = Class.new(parent)
	base.singleton_class.prepend(Describe)
	base.children = Hash.new
	base.subject = subject
	base.description = subject.to_s
	base.identity = Identity.nested(parent.identity, base.description, unique: unique)
	base.set_temporary_name("#{self}[#{base.description}]")
	
	base.define_method(:subject, ->{subject})
	
	if block_given?
		base.class_exec(&block)
	end
	
	return base
end

def print(output)

Print a representation of this describe block.

Signature

parameter output Output

The output target.

Implementation

def print(output)
	output.write(
		"describe ", :describe, self.description, :reset,
		# " ", self.identity.to_s
	)
end