Module: Sus::ItBehavesLike

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

Instance Attribute Summary collapse

Attributes included from Context

#children, #description, #identity

Class Method Summary collapse

Instance Method Summary collapse

Methods included from 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.



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

def shared
  @shared
end

Class Method Details

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sus/it_behaves_like.rb', line 14

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



31
32
33
34
# File 'lib/sus/it_behaves_like.rb', line 31

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