SusSourceSusFile

module File

Represents a test file that can be loaded and executed.

Definitions

def self.[](path)

Load a test file.

Signature

parameter path String

The path to the test file.

returns Class

A test class representing the file.

Implementation

def self.[] path
	self.build(Sus.base, path)
end

def self.extended(base)

Called when this module is extended.

Signature

parameter base Class

The class being extended.

Implementation

def self.extended(base)
	base.children = Hash.new
end

def self.build(parent, path)

Build a test class from a file path.

Signature

parameter parent Class

The parent context class.

parameter path String

The path to the test file.

returns Class

A test class representing the file.

Implementation

def self.build(parent, path)
	base = Class.new(parent)
	
	base.extend(File)
	base.description = path
	base.identity = Identity.file(parent.identity, path)
	base.set_temporary_name("#{self}[#{path}]")
	
	begin
		TOPLEVEL_CLASS_EVAL.call(base, path)
	rescue StandardError, LoadError, SyntaxError => error
		# We add this as a child of the base class so that it is included in the tree under the file rather than completely replacing it, which can be confusing:
		base.add FileLoadError.build(self, path, error)
	end
	
	return base
end

def print(output)

Print a representation of this file context.

Signature

parameter output Output

The output target.

Implementation

def print(output)
	output.write("file ", :path, self.identity, :reset)
end