SusSourceSusItBehavesLike

module ItBehavesLike

Represents a test context that behaves like a shared context.

Definitions

attr_accessor :shared

Signature

attribute Shared

The shared context being used.

def self.build(parent, shared, arguments = nil, unique: false, &block)

Build a new ItBehavesLike context.

Signature

parameter parent Class

The parent context class.

parameter shared Shared

The shared context to use.

parameter arguments Array | Nil

Optional arguments to pass to the shared context.

parameter unique Boolean

Whether the identity should be unique.

yields {...}

Optional block to execute before the shared context.

returns Class

A new test class that behaves like the shared context.

Implementation

def self.build(parent, shared, arguments = nil, unique: false, &block)
	base = Class.new(parent)
	base.singleton_class.prepend(ItBehavesLike)
	base.children = Hash.new
	base.description = shared.name
	base.identity = Identity.nested(parent.identity, base.description, unique: unique)
	base.set_temporary_name("#{self}[#{base.description}]")
	
	# User provided block is evaluated first, so that it can provide default behaviour for the shared context:
	if block_given?
		base.class_exec(*arguments, &block)
	end
	
	base.class_exec(*arguments, &shared.block)
	return base
end

def print(output)

Print a representation of this context.

Signature

parameter output Output

The output target.

Implementation

def print(output)
	self.superclass.print(output)
	output.write(" it behaves like ", :describe, self.description, :reset)
end