Module: Sus::Context
- Included in:
- Describe, File, ItBehavesLike, With
- Defined in:
- lib/sus/it.rb,
lib/sus/let.rb,
lib/sus/file.rb,
lib/sus/with.rb,
lib/sus/context.rb,
lib/sus/describe.rb,
lib/sus/include_context.rb,
lib/sus/it_behaves_like.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#description ⇒ Object
Returns the value of attribute description.
-
#identity ⇒ Object
Returns the value of attribute identity.
Class Method Summary collapse
Instance Method Summary collapse
- #add(child) ⇒ Object
- #call(assertions) ⇒ Object
- #describe(subject, **options, &block) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #file(path) ⇒ Object
- #full_name ⇒ Object
- #include_context(shared, *arguments, **options) ⇒ Object
- #inspect ⇒ Object
- #it ⇒ Object
- #it_behaves_like(shared, *arguments, **options, &block) ⇒ Object
- #leaf? ⇒ Boolean
- #let(name, &block) ⇒ Object
- #print(output) ⇒ Object
- #set_temporary_name(name) ⇒ Object
- #to_s ⇒ Object
- #with(subject = nil, unique: true, **variables, &block) ⇒ Object
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
13 14 15 |
# File 'lib/sus/context.rb', line 13 def children @children end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/sus/context.rb', line 12 def description @description end |
#identity ⇒ Object
Returns the value of attribute identity.
11 12 13 |
# File 'lib/sus/context.rb', line 11 def identity @identity end |
Class Method Details
.extended(base) ⇒ Object
15 16 17 |
# File 'lib/sus/context.rb', line 15 def self.extended(base) base.children = Hash.new end |
Instance Method Details
#add(child) ⇒ Object
37 38 39 |
# File 'lib/sus/context.rb', line 37 def add(child) @children[child.identity] = child end |
#call(assertions) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/sus/context.rb', line 59 def call(assertions) return if self.empty? assertions.nested(self) do |assertions| self.children.each do |identity, child| child.call(assertions) end end end |
#describe(subject, **options, &block) ⇒ Object
41 42 43 |
# File 'lib/sus/describe.rb', line 41 def describe(subject, **, &block) add Describe.build(self, subject, **, &block) end |
#each(&block) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/sus/context.rb', line 69 def each(&block) self.children.each do |identity, child| if child.leaf? yield child else child.each(&block) end end end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/sus/context.rb', line 41 def empty? @children.nil? || @children.empty? end |
#file(path) ⇒ Object
109 110 111 |
# File 'lib/sus/file.rb', line 109 def file(path) add File.build(self, path) end |
#full_name ⇒ Object
53 54 55 56 57 |
# File 'lib/sus/context.rb', line 53 def full_name output = Output::Buffered.new print(output) return output.string end |
#include_context(shared, *arguments, **options) ⇒ Object
10 11 12 |
# File 'lib/sus/include_context.rb', line 10 def include_context(shared, *arguments, **) self.class_exec(*arguments, **, &shared.block) end |
#inspect ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/sus/context.rb', line 28 def inspect if description = self.description "\#<#{self.name || "Context"} #{self.description}>" else self.name end end |
#it_behaves_like(shared, *arguments, **options, &block) ⇒ Object
38 39 40 |
# File 'lib/sus/it_behaves_like.rb', line 38 def it_behaves_like(shared, *arguments, **, &block) add ItBehavesLike.build(self, shared, arguments, **, &block) end |
#leaf? ⇒ Boolean
45 46 47 |
# File 'lib/sus/context.rb', line 45 def leaf? false end |
#let(name, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sus/let.rb', line 10 def let(name, &block) instance_variable = :"@#{name}" self.define_method(name) do if self.instance_variable_defined?(instance_variable) return self.instance_variable_get(instance_variable) else self.instance_variable_set(instance_variable, self.instance_exec(&block)) end end end |
#print(output) ⇒ Object
49 50 51 |
# File 'lib/sus/context.rb', line 49 def print(output) output.write("context ", :context, self.description, :reset) end |
#set_temporary_name(name) ⇒ Object
20 21 22 |
# File 'lib/sus/context.rb', line 20 def set_temporary_name(name) # No-op. end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/sus/context.rb', line 24 def to_s (self.description || self.name).to_s end |