SusSourceSusContext

module Context

Definitions

def before(&hook)

Include an around method to the context class, that invokes the given block before running the test.

Before hooks are usually invoked in the order they are defined, i.e. the first defined hook is invoked first.

Signature

parameter hook Proc

The block to execute before each test.

Implementation

def before(&hook)
	wrapper = Module.new
	
	wrapper.define_method(:before) do
		super()
		
		instance_exec(&hook)
	end
	
	self.include(wrapper)
end

def after(&hook)

Include an around method to the context class, that invokes the given block after running the test.

After hooks are usually invoked in the reverse order they are defined, i.e. the last defined hook is invoked first.

Signature

parameter hook Proc

The block to execute after each test. An error argument is passed if the test failed with an exception.

Implementation

def after(&hook)
	wrapper = Module.new
	
	wrapper.define_method(:after) do |error|
		instance_exec(error, &hook)
	rescue => error
		raise
	ensure
		super(error)
	end
	
	self.include(wrapper)
end

def around(&block)

Add an around hook to the context class.

Around hooks are called in the reverse order they are defined.

The top level around implementation invokes before and after hooks.

Implementation

def around(&block)
	wrapper = Module.new
	
	wrapper.define_method(:around, &block)
	
	self.include(wrapper)
end

def include_context(shared, *arguments, **options)

Include a shared context into the current context, along with any arguments or options.

Signature

parameter shared Sus::Shared

The shared context to include.

parameter arguments Array

The arguments to pass to the shared context.

parameter options Hash

The options to pass to the shared context.

Implementation

def include_context(shared, *arguments, **options)
	self.class_exec(*arguments, **options, &shared.block)
end