Module: Sus::File
- Extended by:
- Context
- Defined in:
- lib/sus/file.rb
Overview
Represents a test file that can be loaded and executed.
Instance Attribute Summary
Attributes included from Context
#The description of this context., #children, #description, #identity
Class Method Summary collapse
-
.[](path) ⇒ Object
Load a test file.
-
.build(parent, path) ⇒ Object
Build a test class from a file path.
-
.extended(base) ⇒ Object
Called when this module is extended.
Instance Method Summary collapse
-
#print(output) ⇒ Object
Print a representation of this file context.
Methods included from Context
The child contexts and tests.=, The identity of this context.=, add, after, around, before, call, describe, each, empty?, file, full_name, include_context, inspect, it, it_behaves_like, leaf?, let, set_temporary_name, to_s, with
Class Method Details
.[](path) ⇒ Object
Load a test file.
34 35 36 |
# File 'lib/sus/file.rb', line 34 def self.[] path self.build(Sus.base, path) end |
.build(parent, path) ⇒ Object
Build a test class from a file path.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sus/file.rb', line 48 def self.build(parent, path) base = Class.new(parent) base.extend(File) base.description = path base.identity = Identity.file(parent.identity, path) base.set_temporary_name("#{self}[#{path}]") begin TOPLEVEL_CLASS_EVAL.call(base, path) rescue StandardError, LoadError, SyntaxError => error # We add this as a child of the base class so that it is included in the tree under the file rather than completely replacing it, which can be confusing: base.add FileLoadError.build(self, path, error) end return base end |
.extended(base) ⇒ Object
Called when this module is extended.
40 41 42 |
# File 'lib/sus/file.rb', line 40 def self.extended(base) base.children = Hash.new end |
Instance Method Details
#print(output) ⇒ Object
Print a representation of this file context.
68 69 70 |
# File 'lib/sus/file.rb', line 68 def print(output) output.write("file ", :path, self.identity, :reset) end |