Module: Sus::With
- Extended by:
- Context
- Defined in:
- lib/sus/with.rb
Overview
Represents a test context with specific conditions or variables.
Instance Attribute Summary collapse
-
#subject ⇒ Object
Returns the value of attribute subject.
- #The subject description of this context.(subjectdescriptionofthiscontext.) ⇒ Object readonly
-
#variables ⇒ Object
Returns the value of attribute variables.
Attributes included from Context
#The description of this context., #children, #description, #identity
Class Method Summary collapse
-
.build(parent, subject, variables, unique: true, &block) ⇒ Object
Build a new with block class.
Instance Method Summary collapse
-
#print(output) ⇒ Object
Print a representation of this with block.
- #The variables available in this context.=(variablesavailable) ⇒ Object
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
#subject ⇒ Object
Returns the value of attribute subject.
14 15 16 |
# File 'lib/sus/with.rb', line 14 def subject @subject end |
#The subject description of this context.(subjectdescriptionofthiscontext.) ⇒ Object (readonly)
14 |
# File 'lib/sus/with.rb', line 14 attr_accessor :subject |
#variables ⇒ Object
Returns the value of attribute variables.
17 18 19 |
# File 'lib/sus/with.rb', line 17 def variables @variables end |
Class Method Details
.build(parent, subject, variables, unique: true, &block) ⇒ Object
Build a new with block class.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sus/with.rb', line 26 def self.build(parent, subject, variables, unique: true, &block) base = Class.new(parent) base.singleton_class.prepend(With) base.children = Hash.new base.subject = subject base.description = subject base.identity = Identity.nested(parent.identity, base.description, unique: unique) base.set_temporary_name("#{self}[#{base.description}]") base.variables = variables base.define_method(:description, ->{subject}) variables.each do |key, value| base.define_method(key, ->{value}) end if block_given? base.class_exec(&block) end return base end |
Instance Method Details
#print(output) ⇒ Object
Print a representation of this with block.
52 53 54 55 56 57 58 59 |
# File 'lib/sus/with.rb', line 52 def print(output) self.superclass.print(output) output.write( " with ", :with, self.description, :reset, # " ", :variables, self.variables.inspect ) end |
#The variables available in this context.=(variablesavailable) ⇒ Object
17 |
# File 'lib/sus/with.rb', line 17 attr_accessor :variables |