Module: Sus::ItBehavesLike

Extended by:
Context
Defined in:
lib/sus/it_behaves_like.rb

Overview

Represents a test context that behaves like a shared context.

Instance Attribute Summary collapse

Attributes included from Context

#The description of this context., #children, #description, #identity

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Context

The child contexts and tests.=, The identity of this context.=, add, after, around, before, call, describe, each, empty?, extended, file, full_name, include_context, inspect, it, it_behaves_like, leaf?, let, set_temporary_name, to_s, with

Instance Attribute Details

#sharedObject

Returns the value of attribute shared.



14
15
16
# File 'lib/sus/it_behaves_like.rb', line 14

def shared
  @shared
end

#The shared context being used.(sharedcontextbeingused.) ⇒ Object (readonly)



14
# File 'lib/sus/it_behaves_like.rb', line 14

attr_accessor :shared

Class Method Details

.build(parent, shared, arguments = nil, unique: false, &block) ⇒ Object

Build a new ItBehavesLike context.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sus/it_behaves_like.rb', line 23

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

Instance Method Details

Print a representation of this context.



42
43
44
45
# File 'lib/sus/it_behaves_like.rb', line 42

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