SusSourceSusIt

module It

Represents an individual test case.

Definitions

def self.build(parent, description = nil, unique: true, &block)

Build a new test case class.

Signature

parameter parent Class

The parent context class.

parameter description String | Nil

Optional description of the test.

parameter unique Boolean

Whether the identity should be unique.

yields {...}

Optional block containing the test code.

returns Class

A new test case class.

Implementation

def self.build(parent, description = nil, unique: true, &block)
	base = Class.new(parent)
	base.extend(It)
	base.description = description
	base.identity = Identity.nested(parent.identity, base.description, unique: unique)
	base.set_temporary_name("#{self}[#{description}]")
	
	if block_given?
		base.define_method(:call, &block)
	end
	
	return base
end

def leaf?

Signature

returns Boolean

Always returns true, as test cases are leaf nodes.

Implementation

def leaf?
	true
end

def print(output)

Print a representation of this test case.

Signature

parameter output Output

The output target.

Implementation

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

def to_s

Signature

returns String

A string representation of this test case.

Implementation

def to_s
	"it #{description}"
end

def call(assertions)

Execute this test case.

Signature

parameter assertions Assertions

The assertions instance to use.

Implementation

def call(assertions)
	assertions.nested(self, identity: self.identity, isolated: true, measure: true) do |assertions|
		instance = self.new(assertions)
		
		instance.around do
			handle_skip(instance, assertions)
		end
	end
end

def handle_skip(instance, assertions)

Handle skip logic for the test case.

Signature

parameter instance Base

The test instance.

parameter assertions Assertions

The assertions instance.

returns Object

The result of calling the test instance.

Implementation

def handle_skip(instance, assertions)
	catch(:skip) do
		return instance.call
	end
end